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

Go to the source code of this file.

Functions

static void L_shift (ULong *x, const ULong *x1, int i)
 
int hexnan (CONST char **sp, FPI *fpi, ULong *x0)
 

Function Documentation

◆ hexnan()

int hexnan ( CONST char **  sp,
FPI fpi,
ULong x0 
)

Definition at line 61 of file hexnan.c.

63 {
64  ULong c, h, *x, *x1, *xe;
65  CONST char* s;
66  int havedig, hd0, i, nbits;
67 
68  if(!hexdig['0'])
69  {
71  }
72  nbits = fpi->nbits;
73  x = x0 + (nbits >> kshift);
74  if(nbits & kmask)
75  {
76  x++;
77  }
78  *--x = 0;
79  x1 = xe = x;
80  havedig = hd0 = i = 0;
81  s = *sp;
82  /* allow optional initial 0x or 0X */
83  while((c = *(CONST unsigned char*)(s + 1)) && c <= ' ')
84  {
85  ++s;
86  }
87  if(s[1] == '0' && (s[2] == 'x' || s[2] == 'X') && *(CONST unsigned char*)(s + 3) > ' ')
88  {
89  s += 2;
90  }
91  while((c = *(CONST unsigned char*)++s))
92  {
93  if(!(h = hexdig[c]))
94  {
95  if(c <= ' ')
96  {
97  if(hd0 < havedig)
98  {
99  if(x < x1 && i < 8)
100  {
101  L_shift(x, x1, i);
102  }
103  if(x <= x0)
104  {
105  i = 8;
106  continue;
107  }
108  hd0 = havedig;
109  *--x = 0;
110  x1 = x;
111  i = 0;
112  }
113  while(*(CONST unsigned char*)(s + 1) <= ' ')
114  {
115  ++s;
116  }
117  if(s[1] == '0' && (s[2] == 'x' || s[2] == 'X') &&
118  *(CONST unsigned char*)(s + 3) > ' ')
119  {
120  s += 2;
121  }
122  continue;
123  }
124  if(/*(*/ c == ')' && havedig)
125  {
126  *sp = s + 1;
127  break;
128  }
129 #ifndef GDTOA_NON_PEDANTIC_NANCHECK
130  do
131  {
132  if(/*(*/ c == ')')
133  {
134  *sp = s + 1;
135  break;
136  }
137  } while((c = (ULong) * ++s));
138 #endif
139  return STRTOG_NaN;
140  }
141  havedig++;
142  if(++i > 8)
143  {
144  if(x <= x0)
145  {
146  continue;
147  }
148  i = 1;
149  *--x = 0;
150  }
151  *x = (*x << 4) | (h & 0xf);
152  }
153  if(!havedig)
154  {
155  return STRTOG_NaN;
156  }
157  if(x < x1 && i < 8)
158  {
159  L_shift(x, x1, i);
160  }
161  if(x > x0)
162  {
163  x1 = x0;
164  do
165  {
166  *x1++ = *x++;
167  } while(x <= xe);
168  do
169  {
170  *x1++ = 0;
171  } while(x1 <= xe);
172  }
173  else
174  {
175  /* truncate high-order word if necessary */
176  if((i = nbits & (ULbits - 1)) != 0)
177  {
178  *xe &= ((ULong)0xffffffff) >> (ULbits - i);
179  }
180  }
181  for(x1 = xe;; --x1)
182  {
183  if(*x1 != 0)
184  {
185  break;
186  }
187  if(x1 == x0)
188  {
189  *x1 = 1;
190  break;
191  }
192  }
193  return STRTOG_NaNbits;
194 }
#define CONST
Definition: gdtoa.h:61
static void L_shift(ULong *x, const ULong *x1, int i)
Definition: hexnan.c:40
#define hexdig
Definition: gdtoaimp.h:523
int nbits
Definition: gdtoa.h:88
#define kshift
Definition: gdtoaimp.h:467
unsigned Long ULong
Definition: gdtoa.h:41
#define kmask
Definition: gdtoaimp.h:468
void hexdig_init_D2A(Void)
Definition: hd_init.c:52
#define ULbits
Definition: gdtoaimp.h:466

References CONST, hexdig, hexdig_init_D2A(), kmask, kshift, L_shift(), FPI::nbits, STRTOG_NaN, STRTOG_NaNbits, and ULbits.

Referenced by strtod(), and strtodg().

◆ L_shift()

static void L_shift ( ULong x,
const ULong x1,
int  i 
)
static

Definition at line 40 of file hexnan.c.

42 {
43  int j;
44 
45  i = 8 - i;
46  i <<= 2;
47  j = ULbits - i;
48  do
49  {
50  *x |= x[1] << j;
51  x[1] >>= i;
52  } while(++x < x1);
53 }
#define ULbits
Definition: gdtoaimp.h:466

References ULbits.

Referenced by hexnan().