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 "."). */
36 ULtodd(L
, bits
, exp
, k
) ULong
*L
; ULong
*bits
; Long exp
; int k
;
38 ULtodd(ULong
*L
, ULong
*bits
, Long exp
, int k
)
43 switch(k
& STRTOG_Retmask
) {
46 L
[0] = L
[1] = L
[2] = L
[3] = 0;
50 L
[_1
] = (bits
[1] >> 21 | bits
[2] << 11) & (ULong
)0xffffffffL
;
51 L
[_0
] = bits
[2] >> 21 | bits
[3] << 11 & 0xfffff
52 | exp
+ 0x3ff + 105 << 20;
54 if (bits
[1] &= 0x1fffff) {
55 i
= hi0bits(bits
[1]) - 11;
63 bits
[1] = bits
[1] << i
| bits
[0] >> 32-i
;
64 bits
[0] = bits
[0] << i
& (ULong
)0xffffffffL
;
68 i
= hi0bits(bits
[0]) + 21;
76 bits
[1] = bits
[0] >> 32 - i
;
77 bits
[0] = bits
[0] << i
& (ULong
)0xffffffffL
;
80 bits
[1] = bits
[0] << i
- 32;
89 L
[2+_0
] = bits
[1] & 0xfffff | exp
<< 20;
97 if (bits
[1] & 0xffe00000)
99 /* completely denormal */
106 i
= hi0bits(bits
[3]) - 11; /* i >= 12 */
108 L
[_0
] = (bits
[3] << i
| bits
[2] >> j
) & 0xfffff
110 L
[_1
] = (bits
[2] << i
| bits
[1] >> j
) & 0xffffffffL
;
111 L
[2+_0
] = bits
[1] & ((ULong
)1L << j
) - 1;
116 i
= hi0bits(bits
[2]) - 11;
120 L
[_0
] = bits
[2] >> j
& 0xfffff | (33 + j
) << 20;
121 L
[_1
] = (bits
[2] << i
| bits
[1] >> j
) & 0xffffffffL
;
122 L
[2+_0
] = bits
[1] & ((ULong
)1L << j
) - 1;
127 L
[_0
] = bits
[2] & 0xfffff | 33 << 20;
134 L
[_0
] = (bits
[2] << i
| bits
[1] >> j
) & 0xfffff
136 L
[_1
] = (bits
[1] << i
| bits
[0] >> j
) & 0xffffffffL
;
138 L
[2+_1
] = bits
[0] & (1L << j
) - 1;
142 j
= 11 - hi0bits(bits
[1]);
144 L
[_0
] = bits
[1] >> j
& 0xfffff | j
+ 1 << 20;
145 L
[_1
] = (bits
[1] << i
| bits
[0] >> j
) & 0xffffffffL
;
147 L
[2+_1
] = bits
[0] & ((ULong
)1L << j
) - 1;
150 case STRTOG_Infinite
:
151 L
[_0
] = L
[2+_0
] = 0x7ff00000;
156 L
[0] = L
[2] = d_QNAN0
;
157 L
[1] = L
[3] = d_QNAN1
;
161 L
[_1
] = (bits
[1] >> 21 | bits
[2] << 11) & (ULong
)0xffffffffL
;
162 L
[_0
] = bits
[2] >> 21 | bits
[3] << 11
163 | (ULong
)0x7ff00000L
;
165 L
[2+_0
] = bits
[1] | (ULong
)0x7ff00000L
;
167 if (k
& STRTOG_Neg
) {
168 L
[_0
] |= 0x80000000L
;
169 L
[2+_0
] |= 0x80000000L
;
175 strtordd(s
, sp
, rounding
, dd
) CONST
char *s
; char **sp
; int rounding
; double *dd
;
177 strtordd(CONST
char *s
, char **sp
, int rounding
, double *dd
)
180 #ifdef Sudden_Underflow
181 static FPI fpi0
= { 106, 1-1023, 2046-1023-106+1, 1, 1 };
183 static FPI fpi0
= { 106, 1-1023-53+1, 2046-1023-106+1, 1, 0 };
191 if (rounding
!= FPI_Round_near
) {
193 fpi1
.rounding
= rounding
;
196 k
= strtodg(s
, sp
, fpi
, &exp
, bits
);
197 ULtodd((ULong
*)dd
, bits
, exp
, k
);