1 /* $NetBSD: strtordd.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 "."). */
38 ULtodd(L
, bits
, expt
, k
) ULong
*L
; ULong
*bits
; Long expt
; int k
;
40 ULtodd(ULong
*L
, ULong
*bits
, Long expt
, int k
)
45 switch(k
& STRTOG_Retmask
) {
48 L
[0] = L
[1] = L
[2] = L
[3] = 0;
52 L
[_1
] = (bits
[1] >> 21 | bits
[2] << 11) & (ULong
)0xffffffffL
;
53 L
[_0
] = (bits
[2] >> 21) | (bits
[3] << 11 & 0xfffff)
54 | ((expt
+ 0x3ff + 105) << 20);
56 if (bits
[1] &= 0x1fffff) {
57 i
= hi0bits(bits
[1]) - 11;
65 bits
[1] = bits
[1] << i
| bits
[0] >> (32-i
);
66 bits
[0] = bits
[0] << i
& (ULong
)0xffffffffL
;
70 i
= hi0bits(bits
[0]) + 21;
78 bits
[1] = bits
[0] >> (32 - i
);
79 bits
[0] = bits
[0] << i
& (ULong
)0xffffffffL
;
82 bits
[1] = bits
[0] << (i
- 32);
91 L
[2+_0
] = (bits
[1] & 0xfffff) | (expt
<< 20);
99 if (bits
[1] & 0xffe00000)
101 /* completely denormal */
108 i
= hi0bits(bits
[3]) - 11; /* i >= 12 */
110 L
[_0
] = ((bits
[3] << i
| bits
[2] >> j
) & 0xfffff)
112 L
[_1
] = (bits
[2] << i
| bits
[1] >> j
) & 0xffffffffL
;
113 L
[2+_0
] = bits
[1] & (((ULong
)1L << j
) - 1);
118 i
= hi0bits(bits
[2]) - 11;
122 L
[_0
] = (bits
[2] >> j
& 0xfffff) | ((33 + j
) << 20);
123 L
[_1
] = (bits
[2] << i
| bits
[1] >> j
) & 0xffffffffL
;
124 L
[2+_0
] = bits
[1] & (((ULong
)1L << j
) - 1);
129 L
[_0
] = (bits
[2] & 0xfffff) | (33 << 20);
136 L
[_0
] = (((bits
[2] << i
) | (bits
[1] >> j
)) & 0xfffff)
138 L
[_1
] = (bits
[1] << i
| bits
[0] >> j
) & 0xffffffffL
;
140 L
[2+_1
] = bits
[0] & ((1L << j
) - 1);
144 j
= 11 - hi0bits(bits
[1]);
146 L
[_0
] = (bits
[1] >> j
& 0xfffff) | ((j
+ 1) << 20);
147 L
[_1
] = (bits
[1] << i
| bits
[0] >> j
) & 0xffffffffL
;
149 L
[2+_1
] = bits
[0] & (((ULong
)1L << j
) - 1);
152 case STRTOG_Infinite
:
153 L
[_0
] = L
[2+_0
] = 0x7ff00000;
158 L
[0] = L
[2] = d_QNAN0
;
159 L
[1] = L
[3] = d_QNAN1
;
163 L
[_1
] = (bits
[1] >> 21 | bits
[2] << 11) & (ULong
)0xffffffffL
;
164 L
[_0
] = bits
[2] >> 21 | bits
[3] << 11
165 | (ULong
)0x7ff00000L
;
167 L
[2+_0
] = bits
[1] | (ULong
)0x7ff00000L
;
169 if (k
& STRTOG_Neg
) {
170 L
[_0
] |= 0x80000000L
;
171 L
[2+_0
] |= 0x80000000L
;
177 strtordd(s
, sp
, rounding
, dd
) CONST
char *s
; char **sp
; int rounding
; double *dd
;
179 strtordd(CONST
char *s
, char **sp
, int rounding
, double *dd
)
182 #ifdef Sudden_Underflow
183 static CONST FPI fpi0
= { 106, 1-1023, 2046-1023-106+1, 1, 1 };
185 static CONST FPI fpi0
= { 106, 1-1023-53+1, 2046-1023-106+1, 1, 0 };
194 if (rounding
!= FPI_Round_near
) {
196 fpi1
.rounding
= rounding
;
199 k
= strtodg(s
, sp
, fpi
, &expt
, bits
);
200 if (k
== STRTOG_NoMemory
)
202 ULtodd((ULong
*)dd
, bits
, expt
, k
);