]>
git.saurik.com Git - apple/libc.git/blob - gdtoa/FreeBSD/gdtoa-hexnan.c
1 /****************************************************************
3 The author of this software is David M. Gay.
5 Copyright (C) 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 "."). */
38 L_shift(x
, x1
, i
) ULong
*x
; ULong
*x1
; int i
;
40 L_shift(ULong
*x
, ULong
*x1
, int i
)
53 #endif /* !__APPLE__ */
58 CONST
char **sp
; CONST FPI
*fpi
; ULong
*x0
;
60 hexnan( CONST
char **sp
, CONST FPI
*fpi
, ULong
*x0
)
66 #else /* !__APPLE__ */
67 ULong c
, h
, *x
, *x1
, *xe
;
68 #endif /* __APPLE__ */
71 int havedig
, hd0
, i
, nbits
;
72 #endif /* !__APPLE__ */
75 if (sp
== NULL
|| *sp
== NULL
|| **sp
!= '(')
77 #else /* !__APPLE__ */
81 x
= x0
+ (nbits
>> kshift
);
86 havedig
= hd0
= i
= 0;
87 #endif /* __APPLE__ */
90 if ((cp
= strchr(s
+ 1, ')')) == NULL
) {
97 #else /* !__APPLE__ */
98 /* allow optional initial 0x or 0X */
99 while((c
= *(CONST
unsigned char*)(s
+1)) && c
<= ' ')
101 if (s
[1] == '0' && (s
[2] == 'x' || s
[2] == 'X')
102 && *(CONST
unsigned char*)(s
+3) > ' ')
104 while((c
= *(CONST
unsigned char*)++s
)) {
105 if (!(h
= hexdig
[c
])) {
119 while(*(CONST
unsigned char*)(s
+1) <= ' ')
121 if (s
[1] == '0' && (s
[2] == 'x' || s
[2] == 'X')
122 && *(CONST
unsigned char*)(s
+3) > ' ')
126 if (/*(*/ c
== ')' && havedig
) {
130 #ifndef GDTOA_NON_PEDANTIC_NANCHECK
132 if (/*(*/ c
== ')') {
138 #endif /* __APPLE__ */
141 strlcpy(cp
, s
+ 1, len
+ 1);
143 #else /* !__APPLE__ */
152 *x
= (*x
<< 4) | (h
& 0xf);
153 #endif /* __APPLE__ */
158 if (nbits
== 52) { /* double */
163 #else /* !__APPLE__ */
174 #endif /* __APPLE__ */
177 else if (nbits
< 52) { /* float */
181 #else /* !__APPLE__ */
183 /* truncate high-order word if necessary */
184 if ( (i
= nbits
& (ULbits
-1)) !=0)
185 *xe
&= ((ULong
)0xffffffff) >> (ULbits
- i
);
186 #endif /* __APPLE__ */
189 else { /* long double */
192 #if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__)
193 x0
[1] = (ULong
)u
.bits
.manh
;
194 x0
[0] = (ULong
)u
.bits
.manl
;
196 #error unsupported architecture
198 #else /* !__APPLE__ */
199 for(x1
= xe
;; --x1
) {
206 #endif /* __APPLE__ */
208 return STRTOG_NaNbits
;