Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
strtorf.c File Reference
#include "gdtoaimp.h"
Include dependency graph for strtorf.c:

Go to the source code of this file.

Functions

void ULtof (ULong *L, const ULong *bits, Long exp, int k)
 
int strtorf (CONST char *s, char **sp, int rounding, float *f)
 

Function Documentation

◆ strtorf()

int strtorf ( CONST char *  s,
char **  sp,
int  rounding,
float *  f 
)

Definition at line 82 of file strtorf.c.

84 {
85  static FPI fpi0 = {24, 1 - 127 - 24 + 1, 254 - 127 - 24 + 1, 1, SI};
86  FPI *fpi, fpi1;
87  ULong bits[1];
88  Long exp;
89  int k;
90 
91  fpi = &fpi0;
92  if(rounding != FPI_Round_near)
93  {
94  fpi1 = fpi0;
95  fpi1.rounding = rounding;
96  fpi = &fpi1;
97  }
98  k = strtodg(s, sp, fpi, &exp, bits);
99  ULtof((ULong*)f, bits, exp, k);
100  return k;
101 }
void ULtof(ULong *L, const ULong *bits, Long exp, int k)
Definition: strtorf.c:41
#define fpi1
#define SI
Definition: gdtoaimp.h:635
unsigned Long ULong
Definition: gdtoa.h:41
Definition: gdtoa.h:86
#define Long
Definition: gdtoa.h:38
int strtodg(CONST char *s00, char **se, FPI *fpi, Long *exp, ULong *bits)
Definition: strtodg.c:443

References fpi1, FPI_Round_near, Long, SI, strtodg(), and ULtof().

◆ ULtof()

void ULtof ( ULong L,
const ULong bits,
Long  exp,
int  k 
)

Definition at line 41 of file strtorf.c.

43 {
44  switch(k & STRTOG_Retmask)
45  {
46  case STRTOG_NoNumber:
47  case STRTOG_Zero:
48  *L = 0;
49  break;
50 
51  case STRTOG_Normal:
52  case STRTOG_NaNbits:
53  L[0] = (bits[0] & 0x7fffff) | (unsigned)((exp + 0x7f + 23) << 23);
54  break;
55 
56  case STRTOG_Denormal:
57  L[0] = bits[0];
58  break;
59 
60  case STRTOG_Infinite:
61  L[0] = 0x7f800000;
62  break;
63 
64  case STRTOG_NaN:
65  L[0] = f_QNAN;
66  }
67  if(k & STRTOG_Neg)
68  {
69  {
70  L[0] |= 0x80000000L;
71  }
72  }
73 }

References STRTOG_Denormal, STRTOG_Infinite, STRTOG_NaN, STRTOG_NaNbits, STRTOG_Neg, STRTOG_NoNumber, STRTOG_Normal, STRTOG_Retmask, and STRTOG_Zero.

Referenced by strtoIf(), and strtorf().