1 /****************************************************************
3 The author of this software is David M. Gay.
5 Copyright (C) 1998, 2000 by Lucent Technologies
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
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
27 ****************************************************************/
29 /* Please send bug reports to David M. Gay (dmg at acm dot org,
30 * with " at " changed at "@" and " dot " changed to "."). */
45 if (!(L
[_1
] | (L
[_0
] & 0xfffff))
46 && (L
[_0
] & 0x7ff00000) > 0x00100000)
53 strtodI(s
, sp
, dd
) CONST
char *s
; char **sp
; double *dd
;
55 strtodI(CONST
char *s
, char **sp
, double *dd
)
58 static FPI fpi
= { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI
};
64 k
= strtodg(s
, sp
, &fpi
, &exp
, bits
);
66 sign
= k
& STRTOG_Neg
? 0x80000000L
: 0;
67 switch(k
& STRTOG_Retmask
) {
69 dval(&u
[0]) = dval(&u
[1]) = 0.;
73 dval(&u
[0]) = dval(&u
[1]) = 0.;
74 #ifdef Sudden_Underflow
75 if (k
& STRTOG_Inexact
) {
77 word0(&u
[0]) = 0x80100000L
;
79 word0(&u
[1]) = 0x100000L
;
87 word1(&u
[0]) = bits
[0];
88 word0(&u
[0]) = bits
[1];
92 word1(&u
[0]) = bits
[0];
93 word0(&u
[0]) = (bits
[1] & ~0x100000) | ((exp
+ 0x3ff + 52) << 20);
95 j
= k
& STRTOG_Inexact
;
98 j
= STRTOG_Inexact
- j
;
102 #ifdef Sudden_Underflow
103 if ((u
->L
[_0
] & 0x7ff00000) < 0x3500000) {
104 word0(&u
[1]) = word0(&u
[0]) + 0x3500000;
105 word1(&u
[1]) = word1(&u
[0]);
106 dval(&u
[1]) += ulp(&u
[1]);
107 word0(&u
[1]) -= 0x3500000;
108 if (!(word0(&u
[1]) & 0x7ff00000)) {
115 dval(&u
[1]) = dval(&u
[0]) + ulp(&u
[0]);
118 dval(&u
[1]) = dval(&u
[0]);
119 #ifdef Sudden_Underflow
120 if ((word0(&u
[0]) & 0x7ff00000) < 0x3500000) {
121 word0(&u
[0]) += 0x3500000;
122 dval(&u
[0]) -= ulpdown(u
);
123 word0(&u
[0]) -= 0x3500000;
124 if (!(word0(&u
[0]) & 0x7ff00000)) {
131 dval(&u
[0]) -= ulpdown(u
);
134 dval(&u
[1]) = dval(&u
[0]);
138 case STRTOG_Infinite
:
139 word0(&u
[0]) = word0(&u
[1]) = sign
| 0x7ff00000;
140 word1(&u
[0]) = word1(&u
[1]) = 0;
141 if (k
& STRTOG_Inexact
) {
143 word0(&u
[1]) = 0xffefffffL
;
144 word1(&u
[1]) = 0xffffffffL
;
147 word0(&u
[0]) = 0x7fefffffL
;
148 word1(&u
[0]) = 0xffffffffL
;
154 u
->L
[0] = (u
+1)->L
[0] = d_QNAN0
;
155 u
->L
[1] = (u
+1)->L
[1] = d_QNAN1
;
159 word0(&u
[0]) = word0(&u
[1]) = 0x7ff00000 | sign
| bits
[1];
160 word1(&u
[0]) = word1(&u
[1]) = bits
[0];