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 29 /* This is a variation on dtoa.c that converts arbitary binary 30 floating-point formats to and from decimal notation. It uses 31 double-precision arithmetic internally, so there are still 32 various #ifdefs that adapt the calculations to the native 33 double-precision arithmetic (any of IEEE, VAX D_floating, 34 or IBM mainframe arithmetic). 35 36 Please send bug reports to David M. Gay (dmg at acm dot org, 37 with " at " changed at "@" and " dot " changed to "."). 38 */ 39 40 /* On a machine with IEEE extended-precision registers, it is 41 * necessary to specify double-precision (53-bit) rounding precision 42 * before invoking strtod or dtoa. If the machine uses (the equivalent 43 * of) Intel 80x87 arithmetic, the call 44 * _control87(PC_53, MCW_PC); 45 * does this with many compilers. Whether this or another call is 46 * appropriate depends on the compiler; for this to work, it may be 47 * necessary to #include "float.h" or another system-dependent header 48 * file. 49 */ 50 51 /* strtod for IEEE-, VAX-, and IBM-arithmetic machines. 52 * 53 * This strtod returns a nearest machine number to the input decimal 54 * string (or sets errno to ERANGE). With IEEE arithmetic, ties are 55 * broken by the IEEE round-even rule. Otherwise ties are broken by 56 * biased rounding (add half and chop). 57 * 58 * Inspired loosely by William D. Clinger's paper "How to Read Floating 59 * Point Numbers Accurately" [Proc. ACM SIGPLAN '90, pp. 112-126]. 60 * 61 * Modifications: 62 * 63 * 1. We only require IEEE, IBM, or VAX double-precision 64 * arithmetic (not IEEE double-extended). 65 * 2. We get by with floating-point arithmetic in a case that 66 * Clinger missed -- when we're computing d * 10^n 67 * for a small integer d and the integer n is not too 68 * much larger than 22 (the maximum integer k for which 69 * we can represent 10^k exactly), we may be able to 70 * compute (d*10^k) * 10^(e-k) with just one roundoff. 71 * 3. Rather than a bit-at-a-time adjustment of the binary 72 * result in the hard case, we use floating-point 73 * arithmetic to determine the adjustment to within 74 * one bit; only in really hard cases do we need to 75 * compute a second residual. 76 * 4. Because of 3., we don't need a large table of powers of 10 77 * for ten-to-e (just some small tables, e.g. of 10^k 78 * for 0 <= k <= 22). 79 */ 80 81 /* 82 * #define IEEE_8087 for IEEE-arithmetic machines where the least 83 * significant byte has the lowest address. 84 * #define IEEE_MC68k for IEEE-arithmetic machines where the most 85 * significant byte has the lowest address. 86 * #define Long int on machines with 32-bit ints and 64-bit longs. 87 * #define Sudden_Underflow for IEEE-format machines without gradual 88 * underflow (i.e., that flush to zero on underflow). 89 * #define IBM for IBM mainframe-style floating-point arithmetic. 90 * #define VAX for VAX-style floating-point arithmetic (D_floating). 91 * #define No_leftright to omit left-right logic in fast floating-point 92 * computation of dtoa and gdtoa. This will cause modes 4 and 5 to be 93 * treated the same as modes 2 and 3 for some inputs. 94 * #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3. 95 * #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines 96 * that use extended-precision instructions to compute rounded 97 * products and quotients) with IBM. 98 * #define ROUND_BIASED for IEEE-format with biased rounding and arithmetic 99 * that rounds toward +Infinity. 100 * #define ROUND_BIASED_without_Round_Up for IEEE-format with biased 101 * rounding when the underlying floating-point arithmetic uses 102 * unbiased rounding. This prevent using ordinary floating-point 103 * arithmetic when the result could be computed with one rounding error. 104 * #define Inaccurate_Divide for IEEE-format with correctly rounded 105 * products but inaccurate quotients, e.g., for Intel i860. 106 * #define NO_LONG_LONG on machines that do not have a "long long" 107 * integer type (of >= 64 bits). On such machines, you can 108 * #define Just_16 to store 16 bits per 32-bit Long when doing 109 * high-precision integer arithmetic. Whether this speeds things 110 * up or slows things down depends on the machine and the number 111 * being converted. If long long is available and the name is 112 * something other than "long long", #define Llong to be the name, 113 * and if "unsigned Llong" does not work as an unsigned version of 114 * Llong, #define #ULLong to be the corresponding unsigned type. 115 * #define KR_headers for old-style C function headers. 116 * #define Bad_float_h if your system lacks a float.h or if it does not 117 * define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP, 118 * FLT_RADIX, FLT_ROUNDS, and DBL_MAX. 119 * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n) 120 * if memory is available and otherwise does something you deem 121 * appropriate. If MALLOC is undefined, malloc will be invoked 122 * directly -- and assumed always to succeed. Similarly, if you 123 * want something other than the system's free() to be called to 124 * recycle memory acquired from MALLOC, #define FREE to be the 125 * name of the alternate routine. (FREE or free is only called in 126 * pathological cases, e.g., in a gdtoa call after a gdtoa return in 127 * mode 3 with thousands of digits requested.) 128 * #define Omit_Private_Memory to omit logic (added Jan. 1998) for making 129 * memory allocations from a private pool of memory when possible. 130 * When used, the private pool is PRIVATE_MEM bytes long: 2304 bytes, 131 * unless #defined to be a different length. This default length 132 * suffices to get rid of MALLOC calls except for unusual cases, 133 * such as decimal-to-binary conversion of a very long string of 134 * digits. When converting IEEE double precision values, the 135 * longest string gdtoa can return is about 751 bytes long. For 136 * conversions by strtod of strings of 800 digits and all gdtoa 137 * conversions of IEEE doubles in single-threaded executions with 138 * 8-byte pointers, PRIVATE_MEM >= 7400 appears to suffice; with 139 * 4-byte pointers, PRIVATE_MEM >= 7112 appears adequate. 140 * #define NO_INFNAN_CHECK if you do not wish to have INFNAN_CHECK 141 * #defined automatically on IEEE systems. On such systems, 142 * when INFNAN_CHECK is #defined, strtod checks 143 * for Infinity and NaN (case insensitively). 144 * When INFNAN_CHECK is #defined and No_Hex_NaN is not #defined, 145 * strtodg also accepts (case insensitively) strings of the form 146 * NaN(x), where x is a string of hexadecimal digits (optionally 147 * preceded by 0x or 0X) and spaces; if there is only one string 148 * of hexadecimal digits, it is taken for the fraction bits of the 149 * resulting NaN; if there are two or more strings of hexadecimal 150 * digits, each string is assigned to the next available sequence 151 * of 32-bit words of fractions bits (starting with the most 152 * significant), right-aligned in each sequence. 153 * Unless GDTOA_NON_PEDANTIC_NANCHECK is #defined, input "NaN(...)" 154 * is consumed even when ... has the wrong form (in which case the 155 * "(...)" is consumed but ignored). 156 * #define MULTIPLE_THREADS if the system offers preemptively scheduled 157 * multiple threads. In this case, you must provide (or suitably 158 * #define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed 159 * by FREE_DTOA_LOCK(n) for n = 0 or 1. (The second lock, accessed 160 * in pow5mult, ensures lazy evaluation of only one copy of high 161 * powers of 5; omitting this lock would introduce a small 162 * probability of wasting memory, but would otherwise be harmless.) 163 * You must also invoke freedtoa(s) to free the value s returned by 164 * dtoa. You may do so whether or not MULTIPLE_THREADS is #defined. 165 * #define IMPRECISE_INEXACT if you do not care about the setting of 166 * the STRTOG_Inexact bits in the special case of doing IEEE double 167 * precision conversions (which could also be done by the strtod in 168 * dtoa.c). 169 * #define NO_HEX_FP to disable recognition of C9x's hexadecimal 170 * floating-point constants. 171 * #define -DNO_ERRNO to suppress setting errno (in strtod.c and 172 * strtodg.c). 173 * #define NO_STRING_H to use private versions of memcpy. 174 * On some K&R systems, it may also be necessary to 175 * #define DECLARE_SIZE_T in this case. 176 * #define USE_LOCALE to use the current locale's decimal_point value. 177 */ 178 179 #ifndef GDTOAIMP_H_INCLUDED 180 #define GDTOAIMP_H_INCLUDED 181 #include "gdtoa.h" 182 183 #if defined(_MSC_VER) 184 /* [RH] Generating gd_qnan.h strikes me as too cumbersome under Visual 185 * Studio, so here's the equivalent, given the limited number of 186 * architectures that MSC can target. (Itanium? Who cares about that?) 187 */ 188 #define f_QNAN 0xffc00000 189 #define d_QNAN0 0x0 190 #define d_QNAN1 0xfff80000 191 #define ld_QNAN0 0x0 192 #define ld_QNAN1 0xfff80000 193 #define ld_QNAN2 0x0 194 #define ld_QNAN3 0x0 195 #define ldus_QNAN0 0x0 196 #define ldus_QNAN1 0x0 197 #define ldus_QNAN2 0x0 198 #define ldus_QNAN3 0xfff8 199 #define ldus_QNAN4 0x0 200 /* [RH] Interestingly, MinGW produces something different because 201 * it turns out that it has a true long double type. I thought that 202 * all ia32 compilers had phased out extended precision. 203 */ 204 #elif defined(__APPLE__) || defined(__ANDROID__) 205 #if defined(__x86_64__) || defined(__i386__) || defined(__ANDROID__) 206 #define f_QNAN 0xffc00000 207 #define d_QNAN0 0x0 208 #define d_QNAN1 0xfff80000 209 #define ld_QNAN0 0x0 210 #define ld_QNAN1 0xc0000000 211 #define ld_QNAN2 0xffff 212 #define ld_QNAN3 0x0 213 #define ldus_QNAN0 0x0 214 #define ldus_QNAN1 0x0 215 #define ldus_QNAN2 0x0 216 #define ldus_QNAN3 0xc000 217 #define ldus_QNAN4 0xffff 218 #else 219 #define f_QNAN 0xffc00000 220 #define d_QNAN0 0xfff80000 221 #define d_QNAN1 0x0 222 #define ld_QNAN0 0xfff80000 223 #define ld_QNAN1 0x0 224 #define ld_QNAN2 0x0 225 #define ld_QNAN3 0x0 226 #define ldus_QNAN0 0xfff8 227 #define ldus_QNAN1 0x0 228 #define ldus_QNAN2 0x0 229 #define ldus_QNAN3 0x0 230 #define ldus_QNAN4 0x0 231 #endif 232 #else 233 #include "gd_qnan.h" 234 #endif 235 236 #ifdef Honor_FLT_ROUNDS 237 #include <fenv.h> 238 #endif 239 240 #ifdef DEBUG 241 #include "stdio.h" 242 #define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);} 243 #endif 244 245 #include "stdlib.h" 246 #include "string.h" 247 248 #ifdef KR_headers 249 #define Char char 250 #else 251 #define Char void 252 #endif 253 254 #ifdef MALLOC 255 extern Char *MALLOC ANSI((size_t)); 256 #else 257 #define MALLOC malloc 258 #endif 259 260 #undef IEEE_Arith 261 #undef Avoid_Underflow 262 #ifdef IEEE_MC68k 263 #define IEEE_Arith 264 #endif 265 #ifdef IEEE_8087 266 #define IEEE_Arith 267 #endif 268 269 #include "errno.h" 270 #ifdef Bad_float_h 271 272 #ifdef IEEE_Arith 273 #define DBL_DIG 15 274 #define DBL_MAX_10_EXP 308 275 #define DBL_MAX_EXP 1024 276 #define FLT_RADIX 2 277 #define DBL_MAX 1.7976931348623157e+308 278 #endif 279 280 #ifdef IBM 281 #define DBL_DIG 16 282 #define DBL_MAX_10_EXP 75 283 #define DBL_MAX_EXP 63 284 #define FLT_RADIX 16 285 #define DBL_MAX 7.2370055773322621e+75 286 #endif 287 288 #ifdef VAX 289 #define DBL_DIG 16 290 #define DBL_MAX_10_EXP 38 291 #define DBL_MAX_EXP 127 292 #define FLT_RADIX 2 293 #define DBL_MAX 1.7014118346046923e+38 294 #define n_bigtens 2 295 #endif 296 297 #ifndef LONG_MAX 298 #define LONG_MAX 2147483647 299 #endif 300 301 #else /* ifndef Bad_float_h */ 302 #include "float.h" 303 #endif /* Bad_float_h */ 304 305 #ifdef IEEE_Arith 306 #define Scale_Bit 0x10 307 #define n_bigtens 5 308 #endif 309 310 #ifdef IBM 311 #define n_bigtens 3 312 #endif 313 314 #ifdef VAX 315 #define n_bigtens 2 316 #endif 317 318 #ifndef __MATH_H__ 319 #include "math.h" 320 #endif 321 322 #ifdef __cplusplus 323 extern "C" { 324 #endif 325 326 #if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1 327 Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined. 328 #endif 329 330 typedef union { double d; ULong L[2]; } U; 331 332 #ifdef IEEE_8087 333 #define word0(x) (x)->L[1] 334 #define word1(x) (x)->L[0] 335 #else 336 #define word0(x) (x)->L[0] 337 #define word1(x) (x)->L[1] 338 #endif 339 #define dval(x) (x)->d 340 341 /* The following definition of Storeinc is appropriate for MIPS processors. 342 * An alternative that might be better on some machines is 343 * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff) 344 */ 345 #if defined(IEEE_8087) + defined(VAX) 346 #define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \ 347 ((unsigned short *)a)[0] = (unsigned short)c, a++) 348 #else 349 #define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \ 350 ((unsigned short *)a)[1] = (unsigned short)c, a++) 351 #endif 352 353 /* #define P DBL_MANT_DIG */ 354 /* Ten_pmax = floor(P*log(2)/log(5)) */ 355 /* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */ 356 /* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */ 357 /* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */ 358 359 #ifdef IEEE_Arith 360 #define Exp_shift 20 361 #define Exp_shift1 20 362 #define Exp_msk1 0x100000 363 #define Exp_msk11 0x100000 364 #define Exp_mask 0x7ff00000 365 #define P 53 366 #define Bias 1023 367 #define Emin (-1022) 368 #define Exp_1 0x3ff00000 369 #define Exp_11 0x3ff00000 370 #define Ebits 11 371 #define Frac_mask 0xfffff 372 #define Frac_mask1 0xfffff 373 #define Ten_pmax 22 374 #define Bletch 0x10 375 #define Bndry_mask 0xfffff 376 #define Bndry_mask1 0xfffff 377 #define LSB 1 378 #define Sign_bit 0x80000000 379 #define Log2P 1 380 #define Tiny0 0 381 #define Tiny1 1 382 #define Quick_max 14 383 #define Int_max 14 384 385 #ifndef Flt_Rounds 386 #ifdef FLT_ROUNDS 387 #define Flt_Rounds FLT_ROUNDS 388 #else 389 #define Flt_Rounds 1 390 #endif 391 #endif /*Flt_Rounds*/ 392 393 #else /* ifndef IEEE_Arith */ 394 #undef Sudden_Underflow 395 #define Sudden_Underflow 396 #ifdef IBM 397 #undef Flt_Rounds 398 #define Flt_Rounds 0 399 #define Exp_shift 24 400 #define Exp_shift1 24 401 #define Exp_msk1 0x1000000 402 #define Exp_msk11 0x1000000 403 #define Exp_mask 0x7f000000 404 #define P 14 405 #define Bias 65 406 #define Exp_1 0x41000000 407 #define Exp_11 0x41000000 408 #define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */ 409 #define Frac_mask 0xffffff 410 #define Frac_mask1 0xffffff 411 #define Bletch 4 412 #define Ten_pmax 22 413 #define Bndry_mask 0xefffff 414 #define Bndry_mask1 0xffffff 415 #define LSB 1 416 #define Sign_bit 0x80000000 417 #define Log2P 4 418 #define Tiny0 0x100000 419 #define Tiny1 0 420 #define Quick_max 14 421 #define Int_max 15 422 #else /* VAX */ 423 #undef Flt_Rounds 424 #define Flt_Rounds 1 425 #define Exp_shift 23 426 #define Exp_shift1 7 427 #define Exp_msk1 0x80 428 #define Exp_msk11 0x800000 429 #define Exp_mask 0x7f80 430 #define P 56 431 #define Bias 129 432 #define Exp_1 0x40800000 433 #define Exp_11 0x4080 434 #define Ebits 8 435 #define Frac_mask 0x7fffff 436 #define Frac_mask1 0xffff007f 437 #define Ten_pmax 24 438 #define Bletch 2 439 #define Bndry_mask 0xffff007f 440 #define Bndry_mask1 0xffff007f 441 #define LSB 0x10000 442 #define Sign_bit 0x8000 443 #define Log2P 1 444 #define Tiny0 0x80 445 #define Tiny1 0 446 #define Quick_max 15 447 #define Int_max 15 448 #endif /* IBM, VAX */ 449 #endif /* IEEE_Arith */ 450 451 #ifndef IEEE_Arith 452 #define ROUND_BIASED 453 #else 454 #ifdef ROUND_BIASED_without_Round_Up 455 #undef ROUND_BIASED 456 #define ROUND_BIASED 457 #endif 458 #endif 459 460 #ifdef RND_PRODQUOT 461 #define rounded_product(a,b) a = rnd_prod(a, b) 462 #define rounded_quotient(a,b) a = rnd_quot(a, b) 463 #ifdef KR_headers 464 extern double rnd_prod(), rnd_quot(); 465 #else 466 extern double rnd_prod(double, double), rnd_quot(double, double); 467 #endif 468 #else 469 #define rounded_product(a,b) a *= b 470 #define rounded_quotient(a,b) a /= b 471 #endif 472 473 #define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1)) 474 #define Big1 0xffffffff 475 476 #undef Pack_16 477 #ifndef Pack_32 478 #define Pack_32 479 #endif 480 481 #ifdef NO_LONG_LONG 482 #undef ULLong 483 #ifdef Just_16 484 #undef Pack_32 485 #define Pack_16 486 /* When Pack_32 is not defined, we store 16 bits per 32-bit Long. 487 * This makes some inner loops simpler and sometimes saves work 488 * during multiplications, but it often seems to make things slightly 489 * slower. Hence the default is now to store 32 bits per Long. 490 */ 491 #endif 492 #else /* long long available */ 493 #ifndef Llong 494 #define Llong long long 495 #endif 496 #ifndef ULLong 497 #define ULLong unsigned Llong 498 #endif 499 #endif /* NO_LONG_LONG */ 500 501 #ifdef Pack_32 502 #define ULbits 32 503 #define kshift 5 504 #define kmask 31 505 #define ALL_ON 0xffffffff 506 #else 507 #define ULbits 16 508 #define kshift 4 509 #define kmask 15 510 #define ALL_ON 0xffff 511 #endif 512 513 //#ifndef MULTIPLE_THREADS 514 #define ACQUIRE_DTOA_LOCK(n) /*nothing*/ 515 #define FREE_DTOA_LOCK(n) /*nothing*/ 516 //#endif 517 518 #define Kmax 9 519 520 struct 521 Bigint { 522 struct Bigint *next; 523 int k, maxwds, sign, wds; 524 ULong x[1]; 525 }; 526 527 typedef struct Bigint Bigint; 528 529 #ifdef NO_STRING_H 530 #ifdef DECLARE_SIZE_T 531 typedef unsigned int size_t; 532 #endif 533 extern void memcpy_D2A ANSI((void*, const void*, size_t)); 534 #define Bcopy(x,y) memcpy_D2A(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int)) 535 #else /* !NO_STRING_H */ 536 #define Bcopy(x,y) memcpy(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int)) 537 #endif /* NO_STRING_H */ 538 539 #define Balloc Balloc_D2A 540 #define Bfree Bfree_D2A 541 #define InfName InfName_D2A 542 #define NanName NanName_D2A 543 #define ULtoQ ULtoQ_D2A 544 #define ULtof ULtof_D2A 545 #define ULtod ULtod_D2A 546 #define ULtodd ULtodd_D2A 547 #define ULtox ULtox_D2A 548 #define ULtoxL ULtoxL_D2A 549 #define add_nanbits add_nanbits_D2A 550 #define any_on any_on_D2A 551 #define b2d b2d_D2A 552 #define bigtens bigtens_D2A 553 #define cmp cmp_D2A 554 #define copybits copybits_D2A 555 #define d2b d2b_D2A 556 #define decrement decrement_D2A 557 #define diff diff_D2A 558 #define dtoa_result dtoa_result_D2A 559 #define g__fmt g__fmt_D2A 560 #define gethex gethex_D2A 561 #define hexdig hexdig_D2A 562 #define hexnan hexnan_D2A 563 #define hi0bits(x) hi0bits_D2A((ULong)(x)) 564 #define i2b i2b_D2A 565 #define increment increment_D2A 566 #define lo0bits lo0bits_D2A 567 #define lshift lshift_D2A 568 #define match match_D2A 569 #define mult mult_D2A 570 #define multadd multadd_D2A 571 #define nrv_alloc nrv_alloc_D2A 572 #define pow5mult pow5mult_D2A 573 #define quorem quorem_D2A 574 #define ratio ratio_D2A 575 #define rshift rshift_D2A 576 #define rv_alloc rv_alloc_D2A 577 #define s2b s2b_D2A 578 #define set_ones set_ones_D2A 579 #define strcp strcp_D2A 580 #define strtoIg strtoIg_D2A 581 #define sum sum_D2A 582 #define tens tens_D2A 583 #define tinytens tinytens_D2A 584 #define tinytens tinytens_D2A 585 #define trailz trailz_D2A 586 #define ulp ulp_D2A 587 588 extern char *add_nanbits ANSI((char*, size_t, ULong*, int)); 589 extern char *dtoa_result; 590 extern CONST double bigtens[], tens[], tinytens[]; 591 extern unsigned char hexdig[]; 592 extern const char *InfName[6], *NanName[3]; 593 594 extern Bigint *Balloc ANSI((int)); 595 extern void Bfree ANSI((Bigint*)); 596 extern void ULtof ANSI((ULong*, ULong*, Long, int)); 597 extern void ULtod ANSI((ULong*, ULong*, Long, int)); 598 extern void ULtodd ANSI((ULong*, ULong*, Long, int)); 599 extern void ULtoQ ANSI((ULong*, ULong*, Long, int)); 600 extern void ULtox ANSI((UShort*, ULong*, Long, int)); 601 extern void ULtoxL ANSI((ULong*, ULong*, Long, int)); 602 extern ULong any_on ANSI((Bigint*, int)); 603 extern double b2d ANSI((Bigint*, int*)); 604 extern int cmp ANSI((Bigint*, Bigint*)); 605 extern void copybits ANSI((ULong*, int, Bigint*)); 606 extern Bigint *d2b ANSI((double, int*, int*)); 607 extern void decrement ANSI((Bigint*)); 608 extern Bigint *diff ANSI((Bigint*, Bigint*)); 609 extern char *dtoa ANSI((double d, int mode, int ndigits, 610 int *decpt, int *sign, char **rve)); 611 extern char *g__fmt ANSI((char*, char*, char*, int, ULong, size_t)); 612 extern int gethex ANSI((CONST char**, FPI*, Long*, Bigint**, int)); 613 extern void hexdig_init_D2A(Void); 614 extern int hexnan ANSI((CONST char**, FPI*, ULong*)); 615 extern int hi0bits_D2A ANSI((ULong)); 616 extern Bigint *i2b ANSI((int)); 617 extern Bigint *increment ANSI((Bigint*)); 618 extern int lo0bits ANSI((ULong*)); 619 extern Bigint *lshift ANSI((Bigint*, int)); 620 extern int match ANSI((CONST char**, char*)); 621 extern Bigint *mult ANSI((Bigint*, Bigint*)); 622 extern Bigint *multadd ANSI((Bigint*, int, int)); 623 extern char *nrv_alloc ANSI((char*, char **, int)); 624 extern Bigint *pow5mult ANSI((Bigint*, int)); 625 extern int quorem ANSI((Bigint*, Bigint*)); 626 extern double ratio ANSI((Bigint*, Bigint*)); 627 extern void rshift ANSI((Bigint*, int)); 628 extern char *rv_alloc ANSI((int)); 629 extern Bigint *s2b ANSI((CONST char*, int, int, ULong, int)); 630 extern Bigint *set_ones ANSI((Bigint*, int)); 631 extern char *strcp ANSI((char*, const char*)); 632 extern int strtoIg ANSI((CONST char*, char**, FPI*, Long*, Bigint**, int*)); 633 // extern double strtod ANSI((const char *s00, char **se)); 634 extern Bigint *sum ANSI((Bigint*, Bigint*)); 635 extern int trailz ANSI((Bigint*)); 636 extern double ulp ANSI((U*)); 637 638 #ifdef __cplusplus 639 } 640 #endif 641 /* 642 * NAN_WORD0 and NAN_WORD1 are only referenced in strtod.c. Prior to 643 * 20050115, they used to be hard-wired here (to 0x7ff80000 and 0, 644 * respectively), but now are determined by compiling and running 645 * qnan.c to generate gd_qnan.h, which specifies d_QNAN0 and d_QNAN1. 646 * Formerly gdtoaimp.h recommended supplying suitable -DNAN_WORD0=... 647 * and -DNAN_WORD1=... values if necessary. This should still work. 648 * (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.) 649 */ 650 #ifdef IEEE_Arith 651 #ifndef NO_INFNAN_CHECK 652 #undef INFNAN_CHECK 653 #define INFNAN_CHECK 654 #endif 655 #ifdef IEEE_MC68k 656 #define _0 0 657 #define _1 1 658 #ifndef NAN_WORD0 659 #define NAN_WORD0 d_QNAN0 660 #endif 661 #ifndef NAN_WORD1 662 #define NAN_WORD1 d_QNAN1 663 #endif 664 #else 665 #define _0 1 666 #define _1 0 667 #ifndef NAN_WORD0 668 #define NAN_WORD0 d_QNAN1 669 #endif 670 #ifndef NAN_WORD1 671 #define NAN_WORD1 d_QNAN0 672 #endif 673 #endif 674 #else 675 #undef INFNAN_CHECK 676 #endif 677 678 #undef SI 679 #ifdef Sudden_Underflow 680 #define SI 1 681 #else 682 #define SI 0 683 #endif 684 685 #endif /* GDTOAIMP_H_INCLUDED */ 686