1 /* $NetBSD: strtodI.c,v 1.3 2011/03/20 23:15:35 christos Exp $ */
3 /****************************************************************
5 The author of this software is David M. Gay.
7 Copyright (C) 1998, 2000 by Lucent Technologies
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
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
29 ****************************************************************/
31 /* Please send bug reports to David M. Gay (dmg at acm dot org,
32 * with " at " changed at "@" and " dot " changed to "."). */
47 if (!(L
[_1
] | (L
[_0
] & 0xfffff))
48 && (L
[_0
] & 0x7ff00000) > 0x00100000)
55 strtodI(s
, sp
, dd
) CONST
char *s
; char **sp
; double *dd
;
57 strtodI(CONST
char *s
, char **sp
, double *dd
)
60 static FPI fpi
= { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI
};
66 k
= strtodg(s
, sp
, &fpi
, &exp
, bits
);
67 if (k
== STRTOG_NoMemory
)
70 sign
= k
& STRTOG_Neg
? 0x80000000L
: 0;
71 switch(k
& STRTOG_Retmask
) {
73 dval(&u
[0]) = dval(&u
[1]) = 0.;
77 dval(&u
[0]) = dval(&u
[1]) = 0.;
78 #ifdef Sudden_Underflow
79 if (k
& STRTOG_Inexact
) {
81 word0(&u
[0]) = 0x80100000L
;
83 word0(&u
[1]) = 0x100000L
;
91 word1(&u
[0]) = bits
[0];
92 word0(&u
[0]) = bits
[1];
96 word1(&u
[0]) = bits
[0];
97 word0(&u
[0]) = (bits
[1] & ~0x100000) | ((exp
+ 0x3ff + 52) << 20);
99 j
= k
& STRTOG_Inexact
;
101 word0(&u
[0]) |= sign
;
102 j
= STRTOG_Inexact
- j
;
106 #ifdef Sudden_Underflow
107 if ((u
->L
[_0
] & 0x7ff00000) < 0x3500000) {
108 word0(&u
[1]) = word0(&u
[0]) + 0x3500000;
109 word1(&u
[1]) = word1(&u
[0]);
110 dval(&u
[1]) += ulp(&u
[1]);
111 word0(&u
[1]) -= 0x3500000;
112 if (!(word0(&u
[1]) & 0x7ff00000)) {
119 dval(&u
[1]) = dval(&u
[0]) + ulp(&u
[0]);
122 dval(&u
[1]) = dval(&u
[0]);
123 #ifdef Sudden_Underflow
124 if ((word0(&u
[0]) & 0x7ff00000) < 0x3500000) {
125 word0(&u
[0]) += 0x3500000;
126 dval(&u
[0]) -= ulpdown(u
);
127 word0(&u
[0]) -= 0x3500000;
128 if (!(word0(&u
[0]) & 0x7ff00000)) {
135 dval(&u
[0]) -= ulpdown(u
);
138 dval(&u
[1]) = dval(&u
[0]);
142 case STRTOG_Infinite
:
143 word0(&u
[0]) = word0(&u
[1]) = sign
| 0x7ff00000;
144 word1(&u
[0]) = word1(&u
[1]) = 0;
145 if (k
& STRTOG_Inexact
) {
147 word0(&u
[1]) = 0xffefffffL
;
148 word1(&u
[1]) = 0xffffffffL
;
151 word0(&u
[0]) = 0x7fefffffL
;
152 word1(&u
[0]) = 0xffffffffL
;
158 u
->L
[0] = (u
+1)->L
[0] = d_QNAN0
;
159 u
->L
[1] = (u
+1)->L
[1] = d_QNAN1
;
163 word0(&u
[0]) = word0(&u
[1]) = 0x7ff00000 | sign
| bits
[1];
164 word1(&u
[0]) = word1(&u
[1]) = bits
[0];