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

Go to the source code of this file.

Functions

void ULtodd (ULong *L, ULong *bits, Long exp, int k)
 
int strtordd (CONST char *s, char **sp, int rounding, double *dd)
 

Function Documentation

◆ strtordd()

int strtordd ( CONST char *  s,
char **  sp,
int  rounding,
double *  dd 
)

Definition at line 212 of file strtordd.c.

214 {
215 #ifdef Sudden_Underflow
216  static FPI fpi0 = {106, 1 - 1023, 2046 - 1023 - 106 + 1, 1, 1};
217 #else
218  static FPI fpi0 = {106, 1 - 1023 - 53 + 1, 2046 - 1023 - 106 + 1, 1, 0};
219 #endif
220  FPI *fpi, fpi1;
221  ULong bits[4];
222  Long exp;
223  int k;
224 
225  fpi = &fpi0;
226  if(rounding != FPI_Round_near)
227  {
228  fpi1 = fpi0;
229  fpi1.rounding = rounding;
230  fpi = &fpi1;
231  }
232  k = strtodg(s, sp, fpi, &exp, bits);
233  ULtodd((ULong*)dd, bits, exp, k);
234  return k;
235 }
void ULtodd(ULong *L, ULong *bits, Long exp, int k)
Definition: strtordd.c:41
#define fpi1
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, strtodg(), and ULtodd().

◆ ULtodd()

void ULtodd ( ULong L,
ULong bits,
Long  exp,
int  k 
)

Definition at line 41 of file strtordd.c.

43 {
44  int i, j;
45 
46  switch(k & STRTOG_Retmask)
47  {
48  case STRTOG_NoNumber:
49  case STRTOG_Zero:
50  L[0] = L[1] = L[2] = L[3] = 0;
51  break;
52 
53  case STRTOG_Normal:
54  L[_1] = (bits[1] >> 21 | bits[2] << 11) & (ULong)0xffffffffL;
55  L[_0] =
56  bits[2] >> 21 | (bits[3] << 11 & 0xfffff) | (unsigned)((exp + 0x3ff + 105) << 20);
57  exp += 0x3ff + 52;
58  if(bits[1] &= 0x1fffff)
59  {
60  i = hi0bits(bits[1]) - 11;
61  if(i >= exp)
62  {
63  i = exp - 1;
64  exp = 0;
65  }
66  else
67  {
68  {
69  exp -= i;
70  }
71  }
72  if(i > 0)
73  {
74  bits[1] = bits[1] << i | bits[0] >> (32 - i);
75  bits[0] = bits[0] << i & (ULong)0xffffffffL;
76  }
77  }
78  else if(bits[0])
79  {
80  i = hi0bits(bits[0]) + 21;
81  if(i >= exp)
82  {
83  i = exp - 1;
84  exp = 0;
85  }
86  else
87  {
88  {
89  exp -= i;
90  }
91  }
92  if(i < 32)
93  {
94  bits[1] = bits[0] >> (32 - i);
95  bits[0] = bits[0] << i & (ULong)0xffffffffL;
96  }
97  else
98  {
99  bits[1] = bits[0] << (i - 32);
100  bits[0] = 0;
101  }
102  }
103  else
104  {
105  L[2] = L[3] = 0;
106  break;
107  }
108  L[2 + _1] = bits[0];
109  L[2 + _0] = (bits[1] & 0xfffff) | (unsigned)(exp << 20);
110  break;
111 
112  case STRTOG_Denormal:
113  if(bits[3])
114  {
115  {
116  goto nearly_normal;
117  }
118  }
119  if(bits[2])
120  {
121  {
122  goto partly_normal;
123  }
124  }
125  if(bits[1] & 0xffe00000)
126  {
127  {
128  goto hardly_normal;
129  }
130  }
131  /* completely denormal */
132  L[2] = L[3] = 0;
133  L[_1] = bits[0];
134  L[_0] = bits[1];
135  break;
136 
137  nearly_normal:
138  i = hi0bits(bits[3]) - 11; /* i >= 12 */
139  j = 32 - i;
140  L[_0] = ((bits[3] << i | bits[2] >> j) & 0xfffff) | (unsigned)((65 - i) << 20);
141  L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL;
142  L[2 + _0] = bits[1] & ((ULong)1L << j) - 1;
143  L[2 + _1] = bits[0];
144  break;
145 
146  partly_normal:
147  i = hi0bits(bits[2]) - 11;
148  if(i < 0)
149  {
150  j = -i;
151  i += 32;
152  L[_0] = (bits[2] >> j & 0xfffff) | (unsigned)((33 + j) << 20);
153  L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL;
154  L[2 + _0] = bits[1] & ((ULong)1L << j) - 1;
155  L[2 + _1] = bits[0];
156  break;
157  }
158  if(i == 0)
159  {
160  L[_0] = (bits[2] & 0xfffff) | 33 << 20;
161  L[_1] = bits[1];
162  L[2 + _0] = 0;
163  L[2 + _1] = bits[0];
164  break;
165  }
166  j = 32 - i;
167  L[_0] = ((bits[2] << i | bits[1] >> j) & 0xfffff) | (unsigned)((j + 1) << 20);
168  L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL;
169  L[2 + _0] = 0;
170  L[2 + _1] = bits[0] & (1L << j) - 1;
171  break;
172 
173  hardly_normal:
174  j = 11 - hi0bits(bits[1]);
175  i = 32 - j;
176  L[_0] = (bits[1] >> j & 0xfffff) | (unsigned)((j + 1) << 20);
177  L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL;
178  L[2 + _0] = 0;
179  L[2 + _1] = bits[0] & ((ULong)1L << j) - 1;
180  break;
181 
182  case STRTOG_Infinite:
183  L[_0] = L[2 + _0] = 0x7ff00000;
184  L[_1] = L[2 + _1] = 0;
185  break;
186 
187  case STRTOG_NaN:
188  L[0] = L[2] = d_QNAN0;
189  L[1] = L[3] = d_QNAN1;
190  break;
191 
192  case STRTOG_NaNbits:
193  L[_1] = (bits[1] >> 21 | bits[2] << 11) & (ULong)0xffffffffL;
194  L[_0] = bits[2] >> 21 | bits[3] << 11 | (ULong)0x7ff00000L;
195  L[2 + _1] = bits[0];
196  L[2 + _0] = bits[1] | (ULong)0x7ff00000L;
197  }
198  if(k & STRTOG_Neg)
199  {
200  L[_0] |= 0x80000000L;
201  L[2 + _0] |= 0x80000000L;
202  }
203 }
#define hi0bits(x)
Definition: gdtoaimp.h:525
unsigned Long ULong
Definition: gdtoa.h:41

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

Referenced by strtoIdd(), and strtordd().