]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | This is a variation on dtoa.c that converts arbitary binary\r | |
3 | floating-point formats to and from decimal notation. It uses\r | |
4 | double-precision arithmetic internally, so there are still\r | |
5 | various #ifdefs that adapt the calculations to the native\r | |
6 | IEEE double-precision arithmetic.\r | |
7 | \r | |
8 | Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r | |
9 | This program and the accompanying materials are licensed and made available under\r | |
10 | the terms and conditions of the BSD License that accompanies this distribution.\r | |
11 | The full text of the license may be found at\r | |
12 | http://opensource.org/licenses/bsd-license.\r | |
13 | \r | |
14 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
15 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
16 | \r | |
17 | *****************************************************************\r | |
18 | \r | |
19 | The author of this software is David M. Gay.\r | |
20 | \r | |
21 | Copyright (C) 1998-2000 by Lucent Technologies\r | |
22 | All Rights Reserved\r | |
23 | \r | |
24 | Permission to use, copy, modify, and distribute this software and\r | |
25 | its documentation for any purpose and without fee is hereby\r | |
26 | granted, provided that the above copyright notice appear in all\r | |
27 | copies and that both that the copyright notice and this\r | |
28 | permission notice and warranty disclaimer appear in supporting\r | |
29 | documentation, and that the name of Lucent or any of its entities\r | |
30 | not be used in advertising or publicity pertaining to\r | |
31 | distribution of the software without specific, written prior\r | |
32 | permission.\r | |
33 | \r | |
34 | LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r | |
35 | INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r | |
36 | IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r | |
37 | SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r | |
38 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r | |
39 | IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r | |
40 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r | |
41 | THIS SOFTWARE.\r | |
42 | \r | |
43 | Please send bug reports to David M. Gay (dmg at acm dot org,\r | |
44 | with " at " changed at "@" and " dot " changed to ".").\r | |
45 | \r | |
46 | *****************************************************************\r | |
47 | \r | |
48 | NetBSD: gdtoaimp.h,v 1.5.4.1 2007/05/07 19:49:06 pavel Exp\r | |
49 | **/\r | |
50 | \r | |
51 | /* On a machine with IEEE extended-precision registers, it is\r | |
52 | * necessary to specify double-precision (53-bit) rounding precision\r | |
53 | * before invoking strtod or dtoa. If the machine uses (the equivalent\r | |
54 | * of) Intel 80x87 arithmetic, the call\r | |
55 | * _control87(PC_53, MCW_PC);\r | |
56 | * does this with many compilers. Whether this or another call is\r | |
57 | * appropriate depends on the compiler; for this to work, it may be\r | |
58 | * necessary to #include "float.h" or another system-dependent header\r | |
59 | * file.\r | |
60 | */\r | |
61 | \r | |
62 | /* strtod for IEEE-, VAX-, and IBM-arithmetic machines.\r | |
63 | *\r | |
64 | * This strtod returns a nearest machine number to the input decimal\r | |
65 | * string (or sets errno to ERANGE). With IEEE arithmetic, ties are\r | |
66 | * broken by the IEEE round-even rule. Otherwise ties are broken by\r | |
67 | * biased rounding (add half and chop).\r | |
68 | *\r | |
69 | * Inspired loosely by William D. Clinger's paper "How to Read Floating\r | |
70 | * Point Numbers Accurately" [Proc. ACM SIGPLAN '90, pp. 112-126].\r | |
71 | *\r | |
72 | * Modifications:\r | |
73 | *\r | |
74 | * 1. We only require IEEE, IBM, or VAX double-precision\r | |
75 | * arithmetic (not IEEE double-extended).\r | |
76 | * 2. We get by with floating-point arithmetic in a case that\r | |
77 | * Clinger missed -- when we're computing d * 10^n\r | |
78 | * for a small integer d and the integer n is not too\r | |
79 | * much larger than 22 (the maximum integer k for which\r | |
80 | * we can represent 10^k exactly), we may be able to\r | |
81 | * compute (d*10^k) * 10^(e-k) with just one roundoff.\r | |
82 | * 3. Rather than a bit-at-a-time adjustment of the binary\r | |
83 | * result in the hard case, we use floating-point\r | |
84 | * arithmetic to determine the adjustment to within\r | |
85 | * one bit; only in really hard cases do we need to\r | |
86 | * compute a second residual.\r | |
87 | * 4. Because of 3., we don't need a large table of powers of 10\r | |
88 | * for ten-to-e (just some small tables, e.g. of 10^k\r | |
89 | * for 0 <= k <= 22).\r | |
90 | */\r | |
91 | \r | |
92 | /*\r | |
93 | * #define IEEE_LITTLE_ENDIAN for IEEE-arithmetic machines where the least\r | |
94 | * significant byte has the lowest address.\r | |
95 | * #define IEEE_BIG_ENDIAN for IEEE-arithmetic machines where the most\r | |
96 | * significant byte has the lowest address.\r | |
97 | * #define Long int on machines with 32-bit ints and 64-bit longs.\r | |
98 | * #define Sudden_Underflow for IEEE-format machines without gradual\r | |
99 | * underflow (i.e., that flush to zero on underflow).\r | |
100 | * #define No_leftright to omit left-right logic in fast floating-point\r | |
101 | * computation of dtoa.\r | |
102 | * #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3.\r | |
103 | * #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines\r | |
104 | * that use extended-precision instructions to compute rounded\r | |
105 | * products and quotients) with IBM.\r | |
106 | * #define ROUND_BIASED for IEEE-format with biased rounding.\r | |
107 | * #define Inaccurate_Divide for IEEE-format with correctly rounded\r | |
108 | * products but inaccurate quotients, e.g., for Intel i860.\r | |
109 | * #define NO_LONG_LONG on machines that do not have a "long long"\r | |
110 | * integer type (of >= 64 bits). On such machines, you can\r | |
111 | * #define Just_16 to store 16 bits per 32-bit Long when doing\r | |
112 | * high-precision integer arithmetic. Whether this speeds things\r | |
113 | * up or slows things down depends on the machine and the number\r | |
114 | * being converted. If long long is available and the name is\r | |
115 | * something other than "long long", #define Llong to be the name,\r | |
116 | * and if "unsigned Llong" does not work as an unsigned version of\r | |
117 | * Llong, #define #ULLong to be the corresponding unsigned type.\r | |
118 | * #define Bad_float_h if your system lacks a float.h or if it does not\r | |
119 | * define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP,\r | |
120 | * FLT_RADIX, FLT_ROUNDS, and DBL_MAX.\r | |
121 | * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n)\r | |
122 | * if memory is available and otherwise does something you deem\r | |
123 | * appropriate. If MALLOC is undefined, malloc will be invoked\r | |
124 | * directly -- and assumed always to succeed.\r | |
125 | * #define Omit_Private_Memory to omit logic (added Jan. 1998) for making\r | |
126 | * memory allocations from a private pool of memory when possible.\r | |
127 | * When used, the private pool is PRIVATE_MEM bytes long: 2304 bytes,\r | |
128 | * unless #defined to be a different length. This default length\r | |
129 | * suffices to get rid of MALLOC calls except for unusual cases,\r | |
130 | * such as decimal-to-binary conversion of a very long string of\r | |
131 | * digits. When converting IEEE double precision values, the\r | |
132 | * longest string gdtoa can return is about 751 bytes long. For\r | |
133 | * conversions by strtod of strings of 800 digits and all gdtoa\r | |
134 | * conversions of IEEE doubles in single-threaded executions with\r | |
135 | * 8-byte pointers, PRIVATE_MEM >= 7400 appears to suffice; with\r | |
136 | * 4-byte pointers, PRIVATE_MEM >= 7112 appears adequate.\r | |
137 | * #define INFNAN_CHECK on IEEE systems to cause strtod to check for\r | |
138 | * Infinity and NaN (case insensitively).\r | |
139 | * When INFNAN_CHECK is #defined and No_Hex_NaN is not #defined,\r | |
140 | * strtodg also accepts (case insensitively) strings of the form\r | |
141 | * NaN(x), where x is a string of hexadecimal digits and spaces;\r | |
142 | * if there is only one string of hexadecimal digits, it is taken\r | |
143 | * for the fraction bits of the resulting NaN; if there are two or\r | |
144 | * more strings of hexadecimal digits, each string is assigned\r | |
145 | * to the next available sequence of 32-bit words of fractions\r | |
146 | * bits (starting with the most significant), right-aligned in\r | |
147 | * each sequence.\r | |
148 | * #define MULTIPLE_THREADS if the system offers preemptively scheduled\r | |
149 | * multiple threads. In this case, you must provide (or suitably\r | |
150 | * #define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed\r | |
151 | * by FREE_DTOA_LOCK(n) for n = 0 or 1. (The second lock, accessed\r | |
152 | * in pow5mult, ensures lazy evaluation of only one copy of high\r | |
153 | * powers of 5; omitting this lock would introduce a small\r | |
154 | * probability of wasting memory, but would otherwise be harmless.)\r | |
155 | * You must also invoke freedtoa(s) to free the value s returned by\r | |
156 | * dtoa. You may do so whether or not MULTIPLE_THREADS is #defined.\r | |
157 | * #define IMPRECISE_INEXACT if you do not care about the setting of\r | |
158 | * the STRTOG_Inexact bits in the special case of doing IEEE double\r | |
159 | * precision conversions (which could also be done by the strtog in\r | |
160 | * dtoa.c).\r | |
161 | * #define NO_HEX_FP to disable recognition of C9x's hexadecimal\r | |
162 | * floating-point constants.\r | |
163 | * #define -DNO_ERRNO to suppress setting errno (in strtod.c and\r | |
164 | * strtodg.c).\r | |
165 | * #define NO_STRING_H to use private versions of memcpy.\r | |
166 | * On some K&R systems, it may also be necessary to\r | |
167 | * #define DECLARE_SIZE_T in this case.\r | |
168 | * #define YES_ALIAS to permit aliasing certain double values with\r | |
169 | * arrays of ULongs. This leads to slightly better code with\r | |
170 | * some compilers and was always used prior to 19990916, but it\r | |
171 | * is not strictly legal and can cause trouble with aggressively\r | |
172 | * optimizing compilers (e.g., gcc 2.95.1 under -O2).\r | |
173 | * #define USE_LOCALE to use the current locale's decimal_point value.\r | |
174 | */\r | |
175 | \r | |
176 | /* #define IEEE_{BIG,LITTLE}_ENDIAN in ${ARCHDIR}/gdtoa/arith.h */\r | |
177 | #include <LibConfig.h>\r | |
178 | \r | |
179 | #include <stdint.h>\r | |
180 | #define Short int16_t\r | |
181 | #define UShort uint16_t\r | |
182 | #define Long int32_t\r | |
183 | #define ULong uint32_t\r | |
184 | #define LLong int64_t\r | |
185 | #define ULLong uint64_t\r | |
186 | \r | |
187 | #define INFNAN_CHECK\r | |
188 | #ifdef _REENTRANT\r | |
189 | #define MULTIPLE_THREADS\r | |
190 | #endif\r | |
191 | #define USE_LOCALE\r | |
192 | \r | |
193 | #ifndef GDTOAIMP_H_INCLUDED\r | |
194 | #define GDTOAIMP_H_INCLUDED\r | |
195 | #include "gdtoa.h"\r | |
196 | #include "gd_qnan.h"\r | |
197 | \r | |
198 | #ifdef DEBUG\r | |
199 | #include "stdio.h"\r | |
200 | #define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);}\r | |
201 | #endif\r | |
202 | \r | |
203 | #include "stdlib.h"\r | |
204 | #include "string.h"\r | |
205 | \r | |
206 | #define Char void\r | |
207 | \r | |
208 | #ifdef MALLOC\r | |
209 | extern Char *MALLOC ANSI((size_t));\r | |
210 | #else\r | |
211 | #define MALLOC malloc\r | |
212 | #endif\r | |
213 | \r | |
214 | #undef IEEE_Arith\r | |
215 | #undef Avoid_Underflow\r | |
216 | #ifdef IEEE_BIG_ENDIAN\r | |
217 | #define IEEE_Arith\r | |
218 | #endif\r | |
219 | #ifdef IEEE_LITTLE_ENDIAN\r | |
220 | #define IEEE_Arith\r | |
221 | #endif\r | |
222 | \r | |
223 | #include "errno.h"\r | |
224 | #ifdef Bad_float_h\r | |
225 | \r | |
226 | #ifdef IEEE_Arith\r | |
227 | #define DBL_DIG 15\r | |
228 | #define DBL_MAX_10_EXP 308\r | |
229 | #define DBL_MAX_EXP 1024\r | |
230 | #define FLT_RADIX 2\r | |
231 | #define DBL_MAX 1.7976931348623157e+308\r | |
232 | #endif\r | |
233 | \r | |
234 | #ifndef LONG_MAX\r | |
235 | #define LONG_MAX 2147483647\r | |
236 | #endif\r | |
237 | \r | |
238 | #else /* ifndef Bad_float_h */\r | |
239 | #include "float.h"\r | |
240 | #endif /* Bad_float_h */\r | |
241 | \r | |
242 | #ifdef IEEE_Arith\r | |
243 | #define Scale_Bit 0x10\r | |
244 | #define n_bigtens 5\r | |
245 | #endif\r | |
246 | \r | |
247 | #include "math.h"\r | |
248 | \r | |
249 | #ifdef __cplusplus\r | |
250 | extern "C" {\r | |
251 | #endif\r | |
252 | \r | |
253 | #if defined(IEEE_LITTLE_ENDIAN) + defined(IEEE_BIG_ENDIAN) != 1\r | |
254 | Exactly one of IEEE_LITTLE_ENDIAN or IEEE_BIG_ENDIAN should be defined.\r | |
255 | #endif\r | |
256 | \r | |
257 | /* This union assumes that:\r | |
258 | sizeof(double) == 8\r | |
259 | sizeof(UINT32) == 4\r | |
260 | \r | |
261 | If this is not the case, the type and dimension of the L member will\r | |
262 | have to be modified.\r | |
263 | */\r | |
264 | typedef union { double d; UINT32 L[2]; } U;\r | |
265 | \r | |
266 | #ifdef YES_ALIAS\r | |
267 | #define dval(x) x\r | |
268 | #ifdef IEEE_LITTLE_ENDIAN\r | |
269 | #define word0(x) ((ULong *)&x)[1]\r | |
270 | #define word1(x) ((ULong *)&x)[0]\r | |
271 | #else\r | |
272 | #define word0(x) ((ULong *)&x)[0]\r | |
273 | #define word1(x) ((ULong *)&x)[1]\r | |
274 | #endif\r | |
275 | #else /* !YES_ALIAS */\r | |
276 | #ifdef IEEE_LITTLE_ENDIAN\r | |
277 | #define word0(x) ( /* LINTED */ (U*)&x)->L[1]\r | |
278 | #define word1(x) ( /* LINTED */ (U*)&x)->L[0]\r | |
279 | #else\r | |
280 | #define word0(x) ( /* LINTED */ (U*)&x)->L[0]\r | |
281 | #define word1(x) ( /* LINTED */ (U*)&x)->L[1]\r | |
282 | #endif\r | |
283 | #define dval(x) ( /* LINTED */ (U*)&x)->d\r | |
284 | #endif /* YES_ALIAS */\r | |
285 | \r | |
286 | /* The following definition of Storeinc is appropriate for MIPS processors.\r | |
287 | * An alternative that might be better on some machines is\r | |
288 | * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff)\r | |
289 | */\r | |
290 | #if defined(IEEE_LITTLE_ENDIAN)\r | |
291 | #define Storeinc(a,b,c) \\r | |
292 | (((unsigned short *)(void *)a)[1] = (unsigned short)b, \\r | |
293 | ((unsigned short *)(void *)a)[0] = (unsigned short)c, \\r | |
294 | a++)\r | |
295 | #else\r | |
296 | #define Storeinc(a,b,c) \\r | |
297 | (((unsigned short *)(void *)a)[0] = (unsigned short)b, \\r | |
298 | ((unsigned short *)(void *)a)[1] = (unsigned short)c, \\r | |
299 | a++)\r | |
300 | #endif\r | |
301 | \r | |
302 | /* #define P DBL_MANT_DIG */\r | |
303 | /* Ten_pmax = floor(P*log(2)/log(5)) */\r | |
304 | /* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */\r | |
305 | /* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */\r | |
306 | /* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */\r | |
307 | \r | |
308 | #ifdef IEEE_Arith\r | |
309 | #define Exp_shift 20\r | |
310 | #define Exp_shift1 20\r | |
311 | #define Exp_msk1 0x100000\r | |
312 | #define Exp_msk11 0x100000\r | |
313 | #define Exp_mask 0x7ff00000\r | |
314 | #define P 53\r | |
315 | #define Bias 1023\r | |
316 | #define Emin (-1022)\r | |
317 | #define Exp_1 0x3ff00000\r | |
318 | #define Exp_11 0x3ff00000\r | |
319 | #define Ebits 11\r | |
320 | #define Frac_mask 0xfffffU\r | |
321 | #define Frac_mask1 0xfffffU\r | |
322 | #define Ten_pmax 22\r | |
323 | #define Bletch 0x10\r | |
324 | #define Bndry_mask 0xfffffU\r | |
325 | #define Bndry_mask1 0xfffffU\r | |
326 | #define LSB 1\r | |
327 | #define Sign_bit 0x80000000\r | |
328 | #define Log2P 1\r | |
329 | #define Tiny0 0\r | |
330 | #define Tiny1 1\r | |
331 | #define Quick_max 14\r | |
332 | #define Int_max 14\r | |
333 | \r | |
334 | #ifndef Flt_Rounds\r | |
335 | #ifdef FLT_ROUNDS\r | |
336 | #define Flt_Rounds FLT_ROUNDS\r | |
337 | #else\r | |
338 | #define Flt_Rounds 1\r | |
339 | #endif\r | |
340 | #endif /*Flt_Rounds*/\r | |
341 | \r | |
342 | #else /* ifndef IEEE_Arith */\r | |
343 | #undef Sudden_Underflow\r | |
344 | #define Sudden_Underflow\r | |
345 | #ifdef IBM\r | |
346 | #undef Flt_Rounds\r | |
347 | #define Flt_Rounds 0\r | |
348 | #define Exp_shift 24\r | |
349 | #define Exp_shift1 24\r | |
350 | #define Exp_msk1 0x1000000\r | |
351 | #define Exp_msk11 0x1000000\r | |
352 | #define Exp_mask 0x7f000000\r | |
353 | #define P 14\r | |
354 | #define Bias 65\r | |
355 | #define Exp_1 0x41000000\r | |
356 | #define Exp_11 0x41000000\r | |
357 | #define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */\r | |
358 | #define Frac_mask 0xffffff\r | |
359 | #define Frac_mask1 0xffffff\r | |
360 | #define Bletch 4\r | |
361 | #define Ten_pmax 22\r | |
362 | #define Bndry_mask 0xefffff\r | |
363 | #define Bndry_mask1 0xffffff\r | |
364 | #define LSB 1\r | |
365 | #define Sign_bit 0x80000000\r | |
366 | #define Log2P 4\r | |
367 | #define Tiny0 0x100000\r | |
368 | #define Tiny1 0\r | |
369 | #define Quick_max 14\r | |
370 | #define Int_max 15\r | |
371 | #else /* VAX */\r | |
372 | #undef Flt_Rounds\r | |
373 | #define Flt_Rounds 1\r | |
374 | #define Exp_shift 23\r | |
375 | #define Exp_shift1 7\r | |
376 | #define Exp_msk1 0x80\r | |
377 | #define Exp_msk11 0x800000\r | |
378 | #define Exp_mask 0x7f80\r | |
379 | #define P 56\r | |
380 | #define Bias 129\r | |
381 | #define Exp_1 0x40800000\r | |
382 | #define Exp_11 0x4080\r | |
383 | #define Ebits 8\r | |
384 | #define Frac_mask 0x7fffff\r | |
385 | #define Frac_mask1 0xffff007f\r | |
386 | #define Ten_pmax 24\r | |
387 | #define Bletch 2\r | |
388 | #define Bndry_mask 0xffff007f\r | |
389 | #define Bndry_mask1 0xffff007f\r | |
390 | #define LSB 0x10000\r | |
391 | #define Sign_bit 0x8000\r | |
392 | #define Log2P 1\r | |
393 | #define Tiny0 0x80\r | |
394 | #define Tiny1 0\r | |
395 | #define Quick_max 15\r | |
396 | #define Int_max 15\r | |
397 | #endif /* IBM, VAX */\r | |
398 | #endif /* IEEE_Arith */\r | |
399 | \r | |
400 | #ifndef IEEE_Arith\r | |
401 | #define ROUND_BIASED\r | |
402 | #endif\r | |
403 | \r | |
404 | #ifdef RND_PRODQUOT\r | |
405 | #define rounded_product(a,b) a = rnd_prod(a, b)\r | |
406 | #define rounded_quotient(a,b) a = rnd_quot(a, b)\r | |
407 | extern double rnd_prod(double, double), rnd_quot(double, double);\r | |
408 | #else\r | |
409 | #define rounded_product(a,b) a *= b\r | |
410 | #define rounded_quotient(a,b) a /= b\r | |
411 | #endif\r | |
412 | \r | |
413 | #define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))\r | |
414 | #define Big1 0xffffffffU\r | |
415 | \r | |
416 | #undef Pack_16\r | |
417 | #ifndef Pack_32\r | |
418 | #define Pack_32\r | |
419 | #endif\r | |
420 | \r | |
421 | #ifdef NO_LONG_LONG\r | |
422 | #undef ULLong\r | |
423 | #ifdef Just_16\r | |
424 | #undef Pack_32\r | |
425 | #define Pack_16\r | |
426 | /* When Pack_32 is not defined, we store 16 bits per 32-bit Long.\r | |
427 | * This makes some inner loops simpler and sometimes saves work\r | |
428 | * during multiplications, but it often seems to make things slightly\r | |
429 | * slower. Hence the default is now to store 32 bits per Long.\r | |
430 | */\r | |
431 | #endif\r | |
432 | #else /* long long available */\r | |
433 | #ifndef Llong\r | |
434 | #define Llong long long\r | |
435 | #endif\r | |
436 | #ifndef ULLong\r | |
437 | #define ULLong unsigned Llong\r | |
438 | #endif\r | |
439 | #endif /* NO_LONG_LONG */\r | |
440 | \r | |
441 | #ifdef Pack_32\r | |
442 | #define ULbits 32\r | |
443 | #define kshift 5\r | |
444 | #define kmask 31\r | |
445 | #define ALL_ON 0xffffffff\r | |
446 | #else\r | |
447 | #define ULbits 16\r | |
448 | #define kshift 4\r | |
449 | #define kmask 15\r | |
450 | #define ALL_ON 0xffff\r | |
451 | #endif\r | |
452 | \r | |
453 | #ifndef MULTIPLE_THREADS\r | |
454 | #define ACQUIRE_DTOA_LOCK(n) /*nothing*/\r | |
455 | #define FREE_DTOA_LOCK(n) /*nothing*/\r | |
456 | #else\r | |
457 | #include "reentrant.h"\r | |
458 | \r | |
459 | extern mutex_t __gdtoa_locks[2];\r | |
460 | \r | |
461 | #define ACQUIRE_DTOA_LOCK(n) \\r | |
462 | do { \\r | |
463 | if (__isthreaded) \\r | |
464 | mutex_lock(&__gdtoa_locks[n]); \\r | |
465 | } while (/* CONSTCOND */ 0)\r | |
466 | #define FREE_DTOA_LOCK(n) \\r | |
467 | do { \\r | |
468 | if (__isthreaded) \\r | |
469 | mutex_unlock(&__gdtoa_locks[n]); \\r | |
470 | } while (/* CONSTCOND */ 0)\r | |
471 | #endif\r | |
472 | \r | |
473 | #define Kmax (sizeof(size_t) << 3)\r | |
474 | \r | |
475 | struct\r | |
476 | Bigint {\r | |
477 | struct Bigint *next;\r | |
478 | int k, maxwds, sign, wds;\r | |
479 | ULong x[1];\r | |
480 | };\r | |
481 | \r | |
482 | typedef struct Bigint Bigint;\r | |
483 | \r | |
484 | #ifdef NO_STRING_H\r | |
485 | #ifdef DECLARE_SIZE_T\r | |
486 | typedef unsigned int size_t;\r | |
487 | #endif\r | |
488 | extern void memcpy_D2A ANSI((void*, const void*, size_t));\r | |
489 | #define Bcopy(x,y) memcpy_D2A(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int))\r | |
490 | #else /* !NO_STRING_H */\r | |
491 | #define Bcopy(x,y) memcpy(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int))\r | |
492 | #endif /* NO_STRING_H */\r | |
493 | \r | |
494 | #define Balloc __Balloc_D2A\r | |
495 | #define Bfree __Bfree_D2A\r | |
496 | #define ULtoQ __ULtoQ_D2A\r | |
497 | #define ULtof __ULtof_D2A\r | |
498 | #define ULtod __ULtod_D2A\r | |
499 | #define ULtodd __ULtodd_D2A\r | |
500 | #define ULtox __ULtox_D2A\r | |
501 | #define ULtoxL __ULtoxL_D2A\r | |
502 | #define any_on __any_on_D2A\r | |
503 | #define b2d __b2d_D2A\r | |
504 | #define bigtens __bigtens_D2A\r | |
505 | #define cmp __cmp_D2A\r | |
506 | #define copybits __copybits_D2A\r | |
507 | #define d2b __d2b_D2A\r | |
508 | #define decrement __decrement_D2A\r | |
509 | #define diff __diff_D2A\r | |
510 | #define dtoa_result __dtoa_result_D2A\r | |
511 | #define g__fmt __g__fmt_D2A\r | |
512 | #define gethex __gethex_D2A\r | |
513 | #define hexdig __hexdig_D2A\r | |
514 | #define hexdig_init_D2A __hexdig_init_D2A\r | |
515 | #define hexnan __hexnan_D2A\r | |
516 | #define hi0bits __hi0bits_D2A\r | |
517 | #define hi0bits_D2A __hi0bits_D2A\r | |
518 | #define i2b __i2b_D2A\r | |
519 | #define increment __increment_D2A\r | |
520 | #define lo0bits __lo0bits_D2A\r | |
521 | #define lshift __lshift_D2A\r | |
522 | #define match __match_D2A\r | |
523 | #define mult __mult_D2A\r | |
524 | #define multadd __multadd_D2A\r | |
525 | #define nrv_alloc __nrv_alloc_D2A\r | |
526 | #define pow5mult __pow5mult_D2A\r | |
527 | #define quorem __quorem_D2A\r | |
528 | #define ratio __ratio_D2A\r | |
529 | #define rshift __rshift_D2A\r | |
530 | #define rv_alloc __rv_alloc_D2A\r | |
531 | #define s2b __s2b_D2A\r | |
532 | #define set_ones __set_ones_D2A\r | |
533 | #define strcp __strcp_D2A\r | |
534 | #define strcp_D2A __strcp_D2A\r | |
535 | #define strtoIg __strtoIg_D2A\r | |
536 | #define sum __sum_D2A\r | |
537 | #define tens __tens_D2A\r | |
538 | #define tinytens __tinytens_D2A\r | |
539 | #define tinytens __tinytens_D2A\r | |
540 | #define trailz __trailz_D2A\r | |
541 | #define ulp __ulp_D2A\r | |
542 | \r | |
543 | extern char *dtoa_result;\r | |
544 | extern CONST double bigtens[], tens[], tinytens[];\r | |
545 | extern unsigned char hexdig[];\r | |
546 | \r | |
547 | extern Bigint *Balloc (int);\r | |
548 | extern void Bfree (Bigint*);\r | |
549 | extern void ULtof (ULong*, ULong*, Long, int);\r | |
550 | extern void ULtod (ULong*, ULong*, Long, int);\r | |
551 | extern void ULtodd (ULong*, ULong*, Long, int);\r | |
552 | extern void ULtoQ (ULong*, ULong*, Long, int);\r | |
553 | extern void ULtox (UShort*, ULong*, Long, int);\r | |
554 | extern void ULtoxL (ULong*, ULong*, Long, int);\r | |
555 | extern ULong any_on (Bigint*, int);\r | |
556 | extern double b2d (Bigint*, int*);\r | |
557 | extern int cmp (Bigint*, Bigint*);\r | |
558 | extern void copybits (ULong*, int, Bigint*);\r | |
559 | extern Bigint *d2b (double, int*, int*);\r | |
560 | extern int decrement (Bigint*);\r | |
561 | extern Bigint *diff (Bigint*, Bigint*);\r | |
562 | extern char *dtoa (double d, int mode, int ndigits,\r | |
563 | int *decpt, int *sign, char **rve);\r | |
564 | extern char *g__fmt (char*, char*, char*, int, ULong);\r | |
565 | extern int gethex (CONST char**, CONST FPI*, Long*, Bigint**, int);\r | |
566 | extern void hexdig_init_D2A(Void);\r | |
567 | extern int hexnan (CONST char**, CONST FPI*, ULong*);\r | |
568 | extern int hi0bits_D2A (ULong);\r | |
569 | extern Bigint *i2b (int);\r | |
570 | extern Bigint *increment (Bigint*);\r | |
571 | extern int lo0bits (ULong*);\r | |
572 | extern Bigint *lshift (Bigint*, int);\r | |
573 | extern int match (CONST char**, CONST char*);\r | |
574 | extern Bigint *mult (Bigint*, Bigint*);\r | |
575 | extern Bigint *multadd (Bigint*, int, int);\r | |
576 | extern char *nrv_alloc (CONST char*, char **, size_t);\r | |
577 | extern Bigint *pow5mult (Bigint*, int);\r | |
578 | extern int quorem (Bigint*, Bigint*);\r | |
579 | extern double ratio (Bigint*, Bigint*);\r | |
580 | extern void rshift (Bigint*, int);\r | |
581 | extern char *rv_alloc (size_t);\r | |
582 | extern Bigint *s2b (CONST char*, int, int, ULong);\r | |
583 | extern Bigint *set_ones (Bigint*, int);\r | |
584 | extern char *strcp (char*, const char*);\r | |
585 | extern int strtoIg (CONST char*, char**, FPI*, Long*, Bigint**, int*);\r | |
586 | extern double strtod (const char *s00, char **se);\r | |
587 | extern Bigint *sum (Bigint*, Bigint*);\r | |
588 | extern int trailz (CONST Bigint*);\r | |
589 | extern double ulp (double);\r | |
590 | \r | |
591 | #ifdef __cplusplus\r | |
592 | }\r | |
593 | #endif\r | |
594 | /*\r | |
595 | * NAN_WORD0 and NAN_WORD1 are only referenced in strtod.c. Prior to\r | |
596 | * 20050115, they used to be hard-wired here (to 0x7ff80000 and 0,\r | |
597 | * respectively), but now are determined by compiling and running\r | |
598 | * qnan.c to generate gd_qnan.h, which specifies d_QNAN0 and d_QNAN1.\r | |
599 | * Formerly gdtoaimp.h recommended supplying suitable -DNAN_WORD0=...\r | |
600 | * and -DNAN_WORD1=... values if necessary. This should still work.\r | |
601 | * (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.)\r | |
602 | */\r | |
603 | #ifdef IEEE_Arith\r | |
604 | #ifdef IEEE_BIG_ENDIAN\r | |
605 | #define _0 0\r | |
606 | #define _1 1\r | |
607 | #ifndef NAN_WORD0\r | |
608 | #define NAN_WORD0 d_QNAN0\r | |
609 | #endif\r | |
610 | #ifndef NAN_WORD1\r | |
611 | #define NAN_WORD1 d_QNAN1\r | |
612 | #endif\r | |
613 | #else\r | |
614 | #define _0 1\r | |
615 | #define _1 0\r | |
616 | #ifndef NAN_WORD0\r | |
617 | #define NAN_WORD0 d_QNAN1\r | |
618 | #endif\r | |
619 | #ifndef NAN_WORD1\r | |
620 | #define NAN_WORD1 d_QNAN0\r | |
621 | #endif\r | |
622 | #endif\r | |
623 | #else\r | |
624 | #undef INFNAN_CHECK\r | |
625 | #endif\r | |
626 | \r | |
627 | #undef SI\r | |
628 | #ifdef Sudden_Underflow\r | |
629 | #define SI 1\r | |
630 | #else\r | |
631 | #define SI 0\r | |
632 | #endif\r | |
633 | \r | |
634 | #endif /* GDTOAIMP_H_INCLUDED */\r |