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