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