]>
Commit | Line | Data |
---|---|---|
9385eb3d A |
1 | /**************************************************************** |
2 | ||
3 | The author of this software is David M. Gay. | |
4 | ||
5 | Copyright (C) 1998, 2000 by Lucent Technologies | |
6 | All Rights Reserved | |
7 | ||
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 | |
16 | permission. | |
17 | ||
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 | |
25 | THIS SOFTWARE. | |
26 | ||
27 | ****************************************************************/ | |
28 | ||
3d9156a7 A |
29 | /* Please send bug reports to David M. Gay (dmg at acm dot org, |
30 | * with " at " changed at "@" and " dot " changed to "."). */ | |
9385eb3d | 31 | |
ad3c9f2a A |
32 | #include "xlocale_private.h" |
33 | ||
9385eb3d A |
34 | #include "gdtoaimp.h" |
35 | ||
36 | #undef _0 | |
37 | #undef _1 | |
38 | ||
39 | /* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */ | |
40 | ||
41 | #ifdef IEEE_MC68k | |
42 | #define _0 0 | |
43 | #define _1 1 | |
44 | #define _2 2 | |
45 | #define _3 3 | |
46 | #define _4 4 | |
47 | #endif | |
48 | #ifdef IEEE_8087 | |
49 | #define _0 4 | |
50 | #define _1 3 | |
51 | #define _2 2 | |
52 | #define _3 1 | |
53 | #define _4 0 | |
54 | #endif | |
55 | ||
56 | int | |
57 | #ifdef KR_headers | |
ad3c9f2a | 58 | strtopx(s, sp, V, loc) CONST char *s; char **sp; void *V; locale_t loc; |
9385eb3d | 59 | #else |
ad3c9f2a | 60 | strtopx(CONST char *s, char **sp, void *V, locale_t loc) |
9385eb3d A |
61 | #endif |
62 | { | |
34e8f829 | 63 | static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI }; |
9385eb3d A |
64 | ULong bits[2]; |
65 | Long exp; | |
66 | int k; | |
67 | UShort *L = (UShort*)V; | |
34e8f829 A |
68 | #ifdef Honor_FLT_ROUNDS |
69 | #include "gdtoa_fltrnds.h" | |
70 | #else | |
71 | #define fpi &fpi0 | |
72 | #endif | |
9385eb3d | 73 | |
ad3c9f2a | 74 | k = strtodg(s, sp, fpi, &exp, bits, loc); |
9385eb3d A |
75 | switch(k & STRTOG_Retmask) { |
76 | case STRTOG_NoNumber: | |
ad3c9f2a A |
77 | L[0] = L[1] = L[2] = L[3] = L[4] = 0; |
78 | return k; // avoid setting sign | |
79 | ||
9385eb3d A |
80 | case STRTOG_Zero: |
81 | L[0] = L[1] = L[2] = L[3] = L[4] = 0; | |
82 | break; | |
83 | ||
9385eb3d | 84 | case STRTOG_Denormal: |
3d9156a7 A |
85 | L[_0] = 0; |
86 | goto normal_bits; | |
87 | ||
88 | case STRTOG_Normal: | |
9385eb3d | 89 | case STRTOG_NaNbits: |
3d9156a7 A |
90 | L[_0] = exp + 0x3fff + 63; |
91 | normal_bits: | |
9385eb3d A |
92 | L[_4] = (UShort)bits[0]; |
93 | L[_3] = (UShort)(bits[0] >> 16); | |
94 | L[_2] = (UShort)bits[1]; | |
95 | L[_1] = (UShort)(bits[1] >> 16); | |
9385eb3d A |
96 | break; |
97 | ||
98 | case STRTOG_Infinite: | |
99 | L[_0] = 0x7fff; | |
1f2f436a A |
100 | L[_1] = 0x8000; |
101 | L[_2] = L[_3] = L[_4] = 0; | |
9385eb3d A |
102 | break; |
103 | ||
104 | case STRTOG_NaN: | |
3d9156a7 A |
105 | L[0] = ldus_QNAN0; |
106 | L[1] = ldus_QNAN1; | |
107 | L[2] = ldus_QNAN2; | |
108 | L[3] = ldus_QNAN3; | |
109 | L[4] = ldus_QNAN4; | |
9385eb3d A |
110 | } |
111 | if (k & STRTOG_Neg) | |
112 | L[_0] |= 0x8000; | |
113 | return k; | |
114 | } |