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

Go to the source code of this file.

Functions

char * g_ffmt (char *buf, float *f, int ndig, unsigned bufsize)
 

Function Documentation

◆ g_ffmt()

char* g_ffmt ( char *  buf,
float *  f,
int  ndig,
unsigned  bufsize 
)

Definition at line 41 of file g_ffmt.c.

43 {
44  static FPI fpi = {24, 1 - 127 - 24 + 1, 254 - 127 - 24 + 1, 1, 0};
45  char *b, *s, *se;
46  ULong bits[1], *L, sign;
47  int decpt, ex, i, mode;
48 
49  if(ndig < 0)
50  {
51  ndig = 0;
52  }
53  if(bufsize < (unsigned)(ndig + 10))
54  {
55  return 0;
56  }
57 
58  L = (ULong*)f;
59  sign = L[0] & 0x80000000L;
60  if((L[0] & 0x7f800000) == 0x7f800000)
61  {
62  /* Infinity or NaN */
63  if(L[0] & 0x7fffff)
64  {
65  return strcp(buf, "NaN");
66  }
67  b = buf;
68  if(sign)
69  {
70  {
71  *b++ = '-';
72  }
73  }
74  return strcp(b, "Infinity");
75  }
76  if(*f == 0.0F)
77  {
78  b = buf;
79 #ifndef IGNORE_ZERO_SIGN
80  if(L[0] & 0x80000000L)
81  {
82  {
83  *b++ = '-';
84  }
85  }
86 #endif
87  *b++ = '0';
88  *b = 0;
89  return b;
90  }
91  bits[0] = L[0] & 0x7fffff;
92  if((ex = (L[0] >> 23) & 0xff) != 0)
93  {
94  {
95  bits[0] |= 0x800000;
96  }
97  }
98  else
99  {
100  {
101  ex = 1;
102  }
103  }
104  ex -= 0x7f + 23;
105  mode = 2;
106  if(ndig <= 0)
107  {
108  if(bufsize < 16)
109  {
110  return 0;
111  }
112  mode = 0;
113  }
114  i = STRTOG_Normal;
115  s = gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se);
116  return g__fmt(buf, s, se, decpt, sign);
117 }
char * g__fmt(char *b, char *s, const char *se, int decpt, ULong sign)
Definition: g__fmt.c:46
char * gdtoa(FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, int *decpt, char **rve)
Definition: gdtoa.c:130
unsigned Long ULong
Definition: gdtoa.h:41
Definition: gdtoa.h:86
#define strcp
Definition: gdtoaimp.h:541

References g__fmt(), gdtoa(), strcp, and STRTOG_Normal.