Rev 4921 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4349 | Serge | 1 | /**************************************************************** |
2 | |||
3 | The author of this software is David M. Gay. |
||
4 | |||
5 | Copyright (C) 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 | |||
29 | /* Please send bug reports to |
||
30 | David M. Gay |
||
31 | Bell Laboratories, Room 2C-463 |
||
32 | 600 Mountain Avenue |
||
33 | Murray Hill, NJ 07974-0636 |
||
34 | U.S.A. |
||
35 | dmg@bell-labs.com |
||
36 | */ |
||
37 | |||
38 | /* Modified 06-21-2006 by Jeff Johnston to work with newlib. */ |
||
39 | |||
40 | #include <_ansi.h> |
||
41 | #include |
||
42 | #include |
||
43 | #include "mprec.h" |
||
44 | #include "gdtoa.h" |
||
45 | |||
46 | #ifdef INFNAN_CHECK |
||
6099 | serge | 47 | int |
48 | _DEFUN (match, (sp, t), |
||
49 | _CONST char **sp _AND |
||
50 | char *t) |
||
51 | { |
||
52 | int c, d; |
||
53 | _CONST char *s = *sp; |
||
54 | |||
55 | while( (d = *t++) !=0) { |
||
56 | if ((c = *++s) >= 'A' && c <= 'Z') |
||
57 | c += 'a' - 'A'; |
||
58 | if (c != d) |
||
59 | return 0; |
||
60 | } |
||
61 | *sp = s + 1; |
||
62 | return 1; |
||
63 | } |
||
64 | |||
4349 | Serge | 65 | static void |
66 | _DEFUN (L_shift, (x, x1, i), |
||
67 | __ULong *x _AND |
||
68 | __ULong *x1 _AND |
||
69 | int i) |
||
70 | { |
||
71 | int j; |
||
72 | |||
73 | i = 8 - i; |
||
74 | i <<= 2; |
||
75 | j = ULbits - i; |
||
76 | do { |
||
77 | *x |= x[1] << j; |
||
78 | x[1] >>= i; |
||
79 | } while(++x < x1); |
||
80 | } |
||
81 | |||
82 | int |
||
83 | _DEFUN (hexnan, (sp, fpi, x0), |
||
84 | _CONST char **sp _AND |
||
4921 | Serge | 85 | _CONST FPI *fpi _AND |
4349 | Serge | 86 | __ULong *x0) |
87 | { |
||
88 | __ULong c, h, *x, *x1, *xe; |
||
89 | _CONST char *s; |
||
90 | int havedig, hd0, i, nbits; |
||
91 | |||
92 | nbits = fpi->nbits; |
||
93 | x = x0 + (nbits >> kshift); |
||
94 | if (nbits & kmask) |
||
95 | x++; |
||
96 | *--x = 0; |
||
97 | x1 = xe = x; |
||
98 | havedig = hd0 = i = 0; |
||
99 | s = *sp; |
||
100 | while((c = *(_CONST unsigned char*)++s)) { |
||
4921 | Serge | 101 | if (!(h = __get_hexdig(c))) { |
4349 | Serge | 102 | if (c <= ' ') { |
103 | if (hd0 < havedig) { |
||
104 | if (x < x1 && i < 8) |
||
105 | L_shift(x, x1, i); |
||
106 | if (x <= x0) { |
||
107 | i = 8; |
||
108 | continue; |
||
109 | } |
||
110 | hd0 = havedig; |
||
111 | *--x = 0; |
||
112 | x1 = x; |
||
113 | i = 0; |
||
114 | } |
||
115 | continue; |
||
116 | } |
||
117 | if (/*(*/ c == ')') { |
||
118 | *sp = s + 1; |
||
119 | break; |
||
120 | } |
||
121 | return STRTOG_NaN; |
||
122 | } |
||
123 | havedig++; |
||
124 | if (++i > 8) { |
||
125 | if (x <= x0) |
||
126 | continue; |
||
127 | i = 1; |
||
128 | *--x = 0; |
||
129 | } |
||
130 | *x = ((*x << 4) | (h & 0xf)); |
||
131 | } |
||
132 | if (!havedig) |
||
133 | return STRTOG_NaN; |
||
134 | if (x < x1 && i < 8) |
||
135 | L_shift(x, x1, i); |
||
136 | if (x > x0) { |
||
137 | x1 = x0; |
||
138 | do *x1++ = *x++; |
||
139 | while(x <= xe); |
||
140 | do *x1++ = 0; |
||
141 | while(x1 <= xe); |
||
142 | } |
||
143 | else { |
||
144 | /* truncate high-order word if necessary */ |
||
145 | if ( (i = nbits & (ULbits-1)) !=0) |
||
146 | *xe &= ((__ULong)0xffffffff) >> (ULbits - i); |
||
147 | } |
||
148 | for(x1 = xe;; --x1) { |
||
149 | if (*x1 != 0) |
||
150 | break; |
||
151 | if (x1 == x0) { |
||
152 | *x1 = 1; |
||
153 | break; |
||
154 | } |
||
155 | } |
||
156 | return STRTOG_NaNbits; |
||
157 | } |
||
158 | #endif /* INFNAN_CHECK */=>=>>>><>=>=>>>>=>>><>=><=>=> |