Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
strtord.c
Go to the documentation of this file.
1 /****************************************************************
2 
3 The author of this software is David M. Gay.
4 
5 Copyright (C) 1998, 2000 by Lucent Technologies
6 All Rights Reserved
7 
8 Permission to use, copy, modify, and distribute this software and
9 its documentation for any purpose and without fee is hereby
10 granted, provided that the above copyright notice appear in all
11 copies and that both that the copyright notice and this
12 permission notice and warranty disclaimer appear in supporting
13 documentation, and that the name of Lucent or any of its entities
14 not be used in advertising or publicity pertaining to
15 distribution of the software without specific, written prior
16 permission.
17 
18 LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
20 IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
21 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
23 IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
25 THIS SOFTWARE.
26 
27 ****************************************************************/
28 
29 /* Please send bug reports to David M. Gay (dmg at acm dot org,
30  * with " at " changed at "@" and " dot " changed to "."). */
31 
32 #include "gdtoaimp.h"
33 
34 void
35 #ifdef KR_headers
36  ULtod(L, bits, exp, k) ULong* L;
37 const ULong* bits;
38 Long exp;
39 int k;
40 #else
41 ULtod(ULong *L, const ULong *bits, Long exp, int k)
42 #endif
43 {
44  switch(k & STRTOG_Retmask)
45  {
46  case STRTOG_NoNumber:
47  case STRTOG_Zero:
48  L[0] = L[1] = 0;
49  break;
50 
51  case STRTOG_Denormal:
52  L[_1] = bits[0];
53  L[_0] = bits[1];
54  break;
55 
56  case STRTOG_Normal:
57  case STRTOG_NaNbits:
58  L[_1] = bits[0];
59  L[_0] = (bits[1] & (unsigned)~0x100000) | (unsigned)((exp + 0x3ff + 52) << 20);
60  break;
61 
62  case STRTOG_Infinite:
63  L[_0] = 0x7ff00000;
64  L[_1] = 0;
65  break;
66 
67  case STRTOG_NaN:
68  L[0] = d_QNAN0;
69  L[1] = d_QNAN1;
70  }
71  if(k & STRTOG_Neg)
72  {
73  {
74  L[_0] |= 0x80000000L;
75  }
76  }
77 }
78 
79 int
80 #ifdef KR_headers
81  strtord(s, sp, rounding, d) CONST char* s;
82 char** sp;
83 int rounding;
84 double* d;
85 #else
86 strtord(CONST char *s, char **sp, int rounding, double *d)
87 #endif
88 {
89  static FPI fpi0 = {53, 1 - 1023 - 53 + 1, 2046 - 1023 - 53 + 1, 1, SI};
90  FPI *fpi, fpi1;
91  ULong bits[2];
92  Long exp;
93  int k;
94 
95  fpi = &fpi0;
96  if(rounding != FPI_Round_near)
97  {
98  fpi1 = fpi0;
99  fpi1.rounding = rounding;
100  fpi = &fpi1;
101  }
102  k = strtodg(s, sp, fpi, &exp, bits);
103  ULtod((ULong*)d, bits, exp, k);
104  return k;
105 }
#define CONST
Definition: gdtoa.h:61
#define fpi1
#define SI
Definition: gdtoaimp.h:635
unsigned Long ULong
Definition: gdtoa.h:41
int strtord(CONST char *s, char **sp, int rounding, double *d)
Definition: strtord.c:86
void ULtod(ULong *L, const ULong *bits, Long exp, int k)
Definition: strtord.c: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