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

Go to the source code of this file.

Functions

float strtof (CONST char *s, char **sp)
 

Function Documentation

◆ strtof()

float strtof ( CONST char *  s,
char **  sp 
)

Definition at line 39 of file strtof.c.

41 {
42  static FPI fpi = {24, 1 - 127 - 24 + 1, 254 - 127 - 24 + 1, 1, SI};
43  ULong bits[1];
44  Long exp;
45  int k;
46  union
47  {
48  ULong L[1];
49  float f;
50  } u;
51 
52  k = strtodg(s, sp, &fpi, &exp, bits);
53  switch(k & STRTOG_Retmask)
54  {
55  case STRTOG_NoNumber:
56  case STRTOG_Zero:
57  u.L[0] = 0;
58  break;
59 
60  case STRTOG_Normal:
61  case STRTOG_NaNbits:
62  u.L[0] = (bits[0] & 0x7fffff) | (unsigned)((exp + 0x7f + 23) << 23);
63  break;
64 
65  case STRTOG_Denormal:
66  u.L[0] = bits[0];
67  break;
68 
69  case STRTOG_Infinite:
70  u.L[0] = 0x7f800000;
71  break;
72 
73  case STRTOG_NaN:
74  u.L[0] = f_QNAN;
75  }
76  if(k & STRTOG_Neg)
77  {
78  {
79  u.L[0] |= 0x80000000L;
80  }
81  }
82  return u.f;
83 }
#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 Long, SI, strtodg(), STRTOG_Denormal, STRTOG_Infinite, STRTOG_NaN, STRTOG_NaNbits, STRTOG_Neg, STRTOG_NoNumber, STRTOG_Normal, STRTOG_Retmask, and STRTOG_Zero.