xref: /dragonfly/contrib/gdtoa/gdtoaimp.h (revision 0d5acd74)
11181b21fSPeter Avalos /****************************************************************
21181b21fSPeter Avalos 
31181b21fSPeter Avalos The author of this software is David M. Gay.
41181b21fSPeter Avalos 
51181b21fSPeter Avalos Copyright (C) 1998-2000 by Lucent Technologies
61181b21fSPeter Avalos All Rights Reserved
71181b21fSPeter Avalos 
81181b21fSPeter Avalos Permission to use, copy, modify, and distribute this software and
91181b21fSPeter Avalos its documentation for any purpose and without fee is hereby
101181b21fSPeter Avalos granted, provided that the above copyright notice appear in all
111181b21fSPeter Avalos copies and that both that the copyright notice and this
121181b21fSPeter Avalos permission notice and warranty disclaimer appear in supporting
131181b21fSPeter Avalos documentation, and that the name of Lucent or any of its entities
141181b21fSPeter Avalos not be used in advertising or publicity pertaining to
151181b21fSPeter Avalos distribution of the software without specific, written prior
161181b21fSPeter Avalos permission.
171181b21fSPeter Avalos 
181181b21fSPeter Avalos LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
191181b21fSPeter Avalos INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
201181b21fSPeter Avalos IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
211181b21fSPeter Avalos SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
221181b21fSPeter Avalos WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
231181b21fSPeter Avalos IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
241181b21fSPeter Avalos ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
251181b21fSPeter Avalos THIS SOFTWARE.
261181b21fSPeter Avalos 
271181b21fSPeter Avalos ****************************************************************/
281181b21fSPeter Avalos 
29*0d5acd74SJohn Marino /* $FreeBSD: head/contrib/gdtoa/gdtoaimp.h 227753 2011-11-20 14:45:42Z theraven $ */
30*0d5acd74SJohn Marino 
311181b21fSPeter Avalos /* This is a variation on dtoa.c that converts arbitary binary
321181b21fSPeter Avalos    floating-point formats to and from decimal notation.  It uses
331181b21fSPeter Avalos    double-precision arithmetic internally, so there are still
341181b21fSPeter Avalos    various #ifdefs that adapt the calculations to the native
351181b21fSPeter Avalos    double-precision arithmetic (any of IEEE, VAX D_floating,
361181b21fSPeter Avalos    or IBM mainframe arithmetic).
371181b21fSPeter Avalos 
381181b21fSPeter Avalos    Please send bug reports to David M. Gay (dmg at acm dot org,
391181b21fSPeter Avalos    with " at " changed at "@" and " dot " changed to ".").
401181b21fSPeter Avalos  */
411181b21fSPeter Avalos 
421181b21fSPeter Avalos /* On a machine with IEEE extended-precision registers, it is
431181b21fSPeter Avalos  * necessary to specify double-precision (53-bit) rounding precision
441181b21fSPeter Avalos  * before invoking strtod or dtoa.  If the machine uses (the equivalent
451181b21fSPeter Avalos  * of) Intel 80x87 arithmetic, the call
461181b21fSPeter Avalos  *	_control87(PC_53, MCW_PC);
471181b21fSPeter Avalos  * does this with many compilers.  Whether this or another call is
481181b21fSPeter Avalos  * appropriate depends on the compiler; for this to work, it may be
491181b21fSPeter Avalos  * necessary to #include "float.h" or another system-dependent header
501181b21fSPeter Avalos  * file.
511181b21fSPeter Avalos  */
521181b21fSPeter Avalos 
531181b21fSPeter Avalos /* strtod for IEEE-, VAX-, and IBM-arithmetic machines.
541181b21fSPeter Avalos  *
551181b21fSPeter Avalos  * This strtod returns a nearest machine number to the input decimal
561181b21fSPeter Avalos  * string (or sets errno to ERANGE).  With IEEE arithmetic, ties are
571181b21fSPeter Avalos  * broken by the IEEE round-even rule.  Otherwise ties are broken by
581181b21fSPeter Avalos  * biased rounding (add half and chop).
591181b21fSPeter Avalos  *
601181b21fSPeter Avalos  * Inspired loosely by William D. Clinger's paper "How to Read Floating
611181b21fSPeter Avalos  * Point Numbers Accurately" [Proc. ACM SIGPLAN '90, pp. 112-126].
621181b21fSPeter Avalos  *
631181b21fSPeter Avalos  * Modifications:
641181b21fSPeter Avalos  *
651181b21fSPeter Avalos  *	1. We only require IEEE, IBM, or VAX double-precision
661181b21fSPeter Avalos  *		arithmetic (not IEEE double-extended).
671181b21fSPeter Avalos  *	2. We get by with floating-point arithmetic in a case that
681181b21fSPeter Avalos  *		Clinger missed -- when we're computing d * 10^n
691181b21fSPeter Avalos  *		for a small integer d and the integer n is not too
701181b21fSPeter Avalos  *		much larger than 22 (the maximum integer k for which
711181b21fSPeter Avalos  *		we can represent 10^k exactly), we may be able to
721181b21fSPeter Avalos  *		compute (d*10^k) * 10^(e-k) with just one roundoff.
731181b21fSPeter Avalos  *	3. Rather than a bit-at-a-time adjustment of the binary
741181b21fSPeter Avalos  *		result in the hard case, we use floating-point
751181b21fSPeter Avalos  *		arithmetic to determine the adjustment to within
761181b21fSPeter Avalos  *		one bit; only in really hard cases do we need to
771181b21fSPeter Avalos  *		compute a second residual.
781181b21fSPeter Avalos  *	4. Because of 3., we don't need a large table of powers of 10
791181b21fSPeter Avalos  *		for ten-to-e (just some small tables, e.g. of 10^k
801181b21fSPeter Avalos  *		for 0 <= k <= 22).
811181b21fSPeter Avalos  */
821181b21fSPeter Avalos 
831181b21fSPeter Avalos /*
841181b21fSPeter Avalos  * #define IEEE_8087 for IEEE-arithmetic machines where the least
851181b21fSPeter Avalos  *	significant byte has the lowest address.
861181b21fSPeter Avalos  * #define IEEE_MC68k for IEEE-arithmetic machines where the most
871181b21fSPeter Avalos  *	significant byte has the lowest address.
881181b21fSPeter Avalos  * #define Long int on machines with 32-bit ints and 64-bit longs.
891181b21fSPeter Avalos  * #define Sudden_Underflow for IEEE-format machines without gradual
901181b21fSPeter Avalos  *	underflow (i.e., that flush to zero on underflow).
911181b21fSPeter Avalos  * #define IBM for IBM mainframe-style floating-point arithmetic.
921181b21fSPeter Avalos  * #define VAX for VAX-style floating-point arithmetic (D_floating).
931181b21fSPeter Avalos  * #define No_leftright to omit left-right logic in fast floating-point
94*0d5acd74SJohn Marino  *	computation of dtoa.
951181b21fSPeter Avalos  * #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3.
961181b21fSPeter Avalos  * #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines
971181b21fSPeter Avalos  *	that use extended-precision instructions to compute rounded
981181b21fSPeter Avalos  *	products and quotients) with IBM.
99ba7b3c3cSPeter Avalos  * #define ROUND_BIASED for IEEE-format with biased rounding and arithmetic
100ba7b3c3cSPeter Avalos  *	that rounds toward +Infinity.
101ba7b3c3cSPeter Avalos  * #define ROUND_BIASED_without_Round_Up for IEEE-format with biased
102ba7b3c3cSPeter Avalos  *	rounding when the underlying floating-point arithmetic uses
103ba7b3c3cSPeter Avalos  *	unbiased rounding.  This prevent using ordinary floating-point
104ba7b3c3cSPeter Avalos  *	arithmetic when the result could be computed with one rounding error.
1051181b21fSPeter Avalos  * #define Inaccurate_Divide for IEEE-format with correctly rounded
1061181b21fSPeter Avalos  *	products but inaccurate quotients, e.g., for Intel i860.
1071181b21fSPeter Avalos  * #define NO_LONG_LONG on machines that do not have a "long long"
1081181b21fSPeter Avalos  *	integer type (of >= 64 bits).  On such machines, you can
1091181b21fSPeter Avalos  *	#define Just_16 to store 16 bits per 32-bit Long when doing
1101181b21fSPeter Avalos  *	high-precision integer arithmetic.  Whether this speeds things
1111181b21fSPeter Avalos  *	up or slows things down depends on the machine and the number
1121181b21fSPeter Avalos  *	being converted.  If long long is available and the name is
1131181b21fSPeter Avalos  *	something other than "long long", #define Llong to be the name,
1141181b21fSPeter Avalos  *	and if "unsigned Llong" does not work as an unsigned version of
1151181b21fSPeter Avalos  *	Llong, #define #ULLong to be the corresponding unsigned type.
1161181b21fSPeter Avalos  * #define KR_headers for old-style C function headers.
1171181b21fSPeter Avalos  * #define Bad_float_h if your system lacks a float.h or if it does not
1181181b21fSPeter Avalos  *	define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP,
1191181b21fSPeter Avalos  *	FLT_RADIX, FLT_ROUNDS, and DBL_MAX.
1201181b21fSPeter Avalos  * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n)
1211181b21fSPeter Avalos  *	if memory is available and otherwise does something you deem
1221181b21fSPeter Avalos  *	appropriate.  If MALLOC is undefined, malloc will be invoked
1232a5b511eSPeter Avalos  *	directly -- and assumed always to succeed.  Similarly, if you
1242a5b511eSPeter Avalos  *	want something other than the system's free() to be called to
1252a5b511eSPeter Avalos  *	recycle memory acquired from MALLOC, #define FREE to be the
1262a5b511eSPeter Avalos  *	name of the alternate routine.  (FREE or free is only called in
1272a5b511eSPeter Avalos  *	pathological cases, e.g., in a gdtoa call after a gdtoa return in
1282a5b511eSPeter Avalos  *	mode 3 with thousands of digits requested.)
1291181b21fSPeter Avalos  * #define Omit_Private_Memory to omit logic (added Jan. 1998) for making
1301181b21fSPeter Avalos  *	memory allocations from a private pool of memory when possible.
1311181b21fSPeter Avalos  *	When used, the private pool is PRIVATE_MEM bytes long:  2304 bytes,
1321181b21fSPeter Avalos  *	unless #defined to be a different length.  This default length
1331181b21fSPeter Avalos  *	suffices to get rid of MALLOC calls except for unusual cases,
1341181b21fSPeter Avalos  *	such as decimal-to-binary conversion of a very long string of
1351181b21fSPeter Avalos  *	digits.  When converting IEEE double precision values, the
1361181b21fSPeter Avalos  *	longest string gdtoa can return is about 751 bytes long.  For
1371181b21fSPeter Avalos  *	conversions by strtod of strings of 800 digits and all gdtoa
1381181b21fSPeter Avalos  *	conversions of IEEE doubles in single-threaded executions with
1391181b21fSPeter Avalos  *	8-byte pointers, PRIVATE_MEM >= 7400 appears to suffice; with
1401181b21fSPeter Avalos  *	4-byte pointers, PRIVATE_MEM >= 7112 appears adequate.
1411181b21fSPeter Avalos  * #define NO_INFNAN_CHECK if you do not wish to have INFNAN_CHECK
1421181b21fSPeter Avalos  *	#defined automatically on IEEE systems.  On such systems,
1431181b21fSPeter Avalos  *	when INFNAN_CHECK is #defined, strtod checks
1441181b21fSPeter Avalos  *	for Infinity and NaN (case insensitively).
1451181b21fSPeter Avalos  *	When INFNAN_CHECK is #defined and No_Hex_NaN is not #defined,
1461181b21fSPeter Avalos  *	strtodg also accepts (case insensitively) strings of the form
1471181b21fSPeter Avalos  *	NaN(x), where x is a string of hexadecimal digits (optionally
1481181b21fSPeter Avalos  *	preceded by 0x or 0X) and spaces; if there is only one string
1491181b21fSPeter Avalos  *	of hexadecimal digits, it is taken for the fraction bits of the
1501181b21fSPeter Avalos  *	resulting NaN; if there are two or more strings of hexadecimal
1511181b21fSPeter Avalos  *	digits, each string is assigned to the next available sequence
1521181b21fSPeter Avalos  *	of 32-bit words of fractions bits (starting with the most
1531181b21fSPeter Avalos  *	significant), right-aligned in each sequence.
1541181b21fSPeter Avalos  *	Unless GDTOA_NON_PEDANTIC_NANCHECK is #defined, input "NaN(...)"
1551181b21fSPeter Avalos  *	is consumed even when ... has the wrong form (in which case the
1561181b21fSPeter Avalos  *	"(...)" is consumed but ignored).
1571181b21fSPeter Avalos  * #define MULTIPLE_THREADS if the system offers preemptively scheduled
1581181b21fSPeter Avalos  *	multiple threads.  In this case, you must provide (or suitably
1591181b21fSPeter Avalos  *	#define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed
1601181b21fSPeter Avalos  *	by FREE_DTOA_LOCK(n) for n = 0 or 1.  (The second lock, accessed
1611181b21fSPeter Avalos  *	in pow5mult, ensures lazy evaluation of only one copy of high
1621181b21fSPeter Avalos  *	powers of 5; omitting this lock would introduce a small
1631181b21fSPeter Avalos  *	probability of wasting memory, but would otherwise be harmless.)
1641181b21fSPeter Avalos  *	You must also invoke freedtoa(s) to free the value s returned by
1651181b21fSPeter Avalos  *	dtoa.  You may do so whether or not MULTIPLE_THREADS is #defined.
1661181b21fSPeter Avalos  * #define IMPRECISE_INEXACT if you do not care about the setting of
1671181b21fSPeter Avalos  *	the STRTOG_Inexact bits in the special case of doing IEEE double
1681181b21fSPeter Avalos  *	precision conversions (which could also be done by the strtod in
1691181b21fSPeter Avalos  *	dtoa.c).
1701181b21fSPeter Avalos  * #define NO_HEX_FP to disable recognition of C9x's hexadecimal
1711181b21fSPeter Avalos  *	floating-point constants.
1721181b21fSPeter Avalos  * #define -DNO_ERRNO to suppress setting errno (in strtod.c and
1731181b21fSPeter Avalos  *	strtodg.c).
1741181b21fSPeter Avalos  * #define NO_STRING_H to use private versions of memcpy.
1751181b21fSPeter Avalos  *	On some K&R systems, it may also be necessary to
1761181b21fSPeter Avalos  *	#define DECLARE_SIZE_T in this case.
1771181b21fSPeter Avalos  * #define USE_LOCALE to use the current locale's decimal_point value.
1781181b21fSPeter Avalos  */
1791181b21fSPeter Avalos 
1801181b21fSPeter Avalos #ifndef GDTOAIMP_H_INCLUDED
1811181b21fSPeter Avalos #define GDTOAIMP_H_INCLUDED
1826c3587b9SPeter Avalos 
183*0d5acd74SJohn Marino #define	Long	int
1846c3587b9SPeter Avalos 
1851181b21fSPeter Avalos #include "gdtoa.h"
1861181b21fSPeter Avalos #include "gd_qnan.h"
1871181b21fSPeter Avalos #ifdef Honor_FLT_ROUNDS
1881181b21fSPeter Avalos #include <fenv.h>
1891181b21fSPeter Avalos #endif
1901181b21fSPeter Avalos 
1911181b21fSPeter Avalos #ifdef DEBUG
1921181b21fSPeter Avalos #include "stdio.h"
1931181b21fSPeter Avalos #define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);}
1941181b21fSPeter Avalos #endif
1951181b21fSPeter Avalos 
1966c3587b9SPeter Avalos #include "limits.h"
1971181b21fSPeter Avalos #include "stdlib.h"
1981181b21fSPeter Avalos #include "string.h"
1996c3587b9SPeter Avalos #include "libc_private.h"
2006c3587b9SPeter Avalos 
2016c3587b9SPeter Avalos #include "namespace.h"
2026c3587b9SPeter Avalos #include <pthread.h>
2036c3587b9SPeter Avalos #include "un-namespace.h"
204*0d5acd74SJohn Marino #include "xlocale_private.h"
2051181b21fSPeter Avalos 
2061181b21fSPeter Avalos #ifdef KR_headers
2071181b21fSPeter Avalos #define Char char
2081181b21fSPeter Avalos #else
2091181b21fSPeter Avalos #define Char void
2101181b21fSPeter Avalos #endif
2111181b21fSPeter Avalos 
2121181b21fSPeter Avalos #ifdef MALLOC
2131181b21fSPeter Avalos extern Char *MALLOC ANSI((size_t));
2141181b21fSPeter Avalos #else
2151181b21fSPeter Avalos #define MALLOC malloc
2161181b21fSPeter Avalos #endif
2171181b21fSPeter Avalos 
218*0d5acd74SJohn Marino #define INFNAN_CHECK
219*0d5acd74SJohn Marino #define USE_LOCALE
220*0d5acd74SJohn Marino #define NO_LOCALE_CACHE
221*0d5acd74SJohn Marino #define Honor_FLT_ROUNDS
222*0d5acd74SJohn Marino #define Trust_FLT_ROUNDS
223*0d5acd74SJohn Marino 
2241181b21fSPeter Avalos #undef IEEE_Arith
2251181b21fSPeter Avalos #undef Avoid_Underflow
2261181b21fSPeter Avalos #ifdef IEEE_MC68k
2271181b21fSPeter Avalos #define IEEE_Arith
2281181b21fSPeter Avalos #endif
2291181b21fSPeter Avalos #ifdef IEEE_8087
2301181b21fSPeter Avalos #define IEEE_Arith
2311181b21fSPeter Avalos #endif
2321181b21fSPeter Avalos 
2331181b21fSPeter Avalos #include "errno.h"
2341181b21fSPeter Avalos #ifdef Bad_float_h
2351181b21fSPeter Avalos 
2361181b21fSPeter Avalos #ifdef IEEE_Arith
2371181b21fSPeter Avalos #define DBL_DIG 15
2381181b21fSPeter Avalos #define DBL_MAX_10_EXP 308
2391181b21fSPeter Avalos #define DBL_MAX_EXP 1024
2401181b21fSPeter Avalos #define FLT_RADIX 2
2411181b21fSPeter Avalos #define DBL_MAX 1.7976931348623157e+308
2421181b21fSPeter Avalos #endif
2431181b21fSPeter Avalos 
2441181b21fSPeter Avalos #ifdef IBM
2451181b21fSPeter Avalos #define DBL_DIG 16
2461181b21fSPeter Avalos #define DBL_MAX_10_EXP 75
2471181b21fSPeter Avalos #define DBL_MAX_EXP 63
2481181b21fSPeter Avalos #define FLT_RADIX 16
2491181b21fSPeter Avalos #define DBL_MAX 7.2370055773322621e+75
2501181b21fSPeter Avalos #endif
2511181b21fSPeter Avalos 
2521181b21fSPeter Avalos #ifdef VAX
2531181b21fSPeter Avalos #define DBL_DIG 16
2541181b21fSPeter Avalos #define DBL_MAX_10_EXP 38
2551181b21fSPeter Avalos #define DBL_MAX_EXP 127
2561181b21fSPeter Avalos #define FLT_RADIX 2
2571181b21fSPeter Avalos #define DBL_MAX 1.7014118346046923e+38
2581181b21fSPeter Avalos #define n_bigtens 2
2591181b21fSPeter Avalos #endif
2601181b21fSPeter Avalos 
2611181b21fSPeter Avalos #ifndef LONG_MAX
2621181b21fSPeter Avalos #define LONG_MAX 2147483647
2631181b21fSPeter Avalos #endif
2641181b21fSPeter Avalos 
2651181b21fSPeter Avalos #else /* ifndef Bad_float_h */
2661181b21fSPeter Avalos #include "float.h"
2671181b21fSPeter Avalos #endif /* Bad_float_h */
2681181b21fSPeter Avalos 
2691181b21fSPeter Avalos #ifdef IEEE_Arith
2701181b21fSPeter Avalos #define Scale_Bit 0x10
2711181b21fSPeter Avalos #define n_bigtens 5
2721181b21fSPeter Avalos #endif
2731181b21fSPeter Avalos 
2741181b21fSPeter Avalos #ifdef IBM
2751181b21fSPeter Avalos #define n_bigtens 3
2761181b21fSPeter Avalos #endif
2771181b21fSPeter Avalos 
2781181b21fSPeter Avalos #ifdef VAX
2791181b21fSPeter Avalos #define n_bigtens 2
2801181b21fSPeter Avalos #endif
2811181b21fSPeter Avalos 
2821181b21fSPeter Avalos #ifndef __MATH_H__
2831181b21fSPeter Avalos #include "math.h"
2841181b21fSPeter Avalos #endif
2851181b21fSPeter Avalos 
2861181b21fSPeter Avalos #ifdef __cplusplus
2871181b21fSPeter Avalos extern "C" {
2881181b21fSPeter Avalos #endif
2891181b21fSPeter Avalos 
2901181b21fSPeter Avalos #if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1
2911181b21fSPeter Avalos Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined.
2921181b21fSPeter Avalos #endif
2931181b21fSPeter Avalos 
2941181b21fSPeter Avalos typedef union { double d; ULong L[2]; } U;
2951181b21fSPeter Avalos 
2961181b21fSPeter Avalos #ifdef IEEE_8087
2972a5b511eSPeter Avalos #define word0(x) (x)->L[1]
2982a5b511eSPeter Avalos #define word1(x) (x)->L[0]
2991181b21fSPeter Avalos #else
3002a5b511eSPeter Avalos #define word0(x) (x)->L[0]
3012a5b511eSPeter Avalos #define word1(x) (x)->L[1]
3021181b21fSPeter Avalos #endif
3032a5b511eSPeter Avalos #define dval(x) (x)->d
3041181b21fSPeter Avalos 
3051181b21fSPeter Avalos /* The following definition of Storeinc is appropriate for MIPS processors.
3061181b21fSPeter Avalos  * An alternative that might be better on some machines is
3071181b21fSPeter Avalos  * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff)
3081181b21fSPeter Avalos  */
3091181b21fSPeter Avalos #if defined(IEEE_8087) + defined(VAX)
3101181b21fSPeter Avalos #define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \
3111181b21fSPeter Avalos ((unsigned short *)a)[0] = (unsigned short)c, a++)
3121181b21fSPeter Avalos #else
3131181b21fSPeter Avalos #define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \
3141181b21fSPeter Avalos ((unsigned short *)a)[1] = (unsigned short)c, a++)
3151181b21fSPeter Avalos #endif
3161181b21fSPeter Avalos 
3171181b21fSPeter Avalos /* #define P DBL_MANT_DIG */
3181181b21fSPeter Avalos /* Ten_pmax = floor(P*log(2)/log(5)) */
3191181b21fSPeter Avalos /* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */
3201181b21fSPeter Avalos /* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */
3211181b21fSPeter Avalos /* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */
3221181b21fSPeter Avalos 
3231181b21fSPeter Avalos #ifdef IEEE_Arith
3241181b21fSPeter Avalos #define Exp_shift  20
3251181b21fSPeter Avalos #define Exp_shift1 20
3261181b21fSPeter Avalos #define Exp_msk1    0x100000
3271181b21fSPeter Avalos #define Exp_msk11   0x100000
3281181b21fSPeter Avalos #define Exp_mask  0x7ff00000
3291181b21fSPeter Avalos #define P 53
3301181b21fSPeter Avalos #define Bias 1023
3311181b21fSPeter Avalos #define Emin (-1022)
3321181b21fSPeter Avalos #define Exp_1  0x3ff00000
3331181b21fSPeter Avalos #define Exp_11 0x3ff00000
3341181b21fSPeter Avalos #define Ebits 11
3351181b21fSPeter Avalos #define Frac_mask  0xfffff
3361181b21fSPeter Avalos #define Frac_mask1 0xfffff
3371181b21fSPeter Avalos #define Ten_pmax 22
3381181b21fSPeter Avalos #define Bletch 0x10
3391181b21fSPeter Avalos #define Bndry_mask  0xfffff
3401181b21fSPeter Avalos #define Bndry_mask1 0xfffff
3411181b21fSPeter Avalos #define LSB 1
3421181b21fSPeter Avalos #define Sign_bit 0x80000000
3431181b21fSPeter Avalos #define Log2P 1
3441181b21fSPeter Avalos #define Tiny0 0
3451181b21fSPeter Avalos #define Tiny1 1
3461181b21fSPeter Avalos #define Quick_max 14
3471181b21fSPeter Avalos #define Int_max 14
3481181b21fSPeter Avalos 
3491181b21fSPeter Avalos #ifndef Flt_Rounds
3501181b21fSPeter Avalos #ifdef FLT_ROUNDS
3511181b21fSPeter Avalos #define Flt_Rounds FLT_ROUNDS
3521181b21fSPeter Avalos #else
3531181b21fSPeter Avalos #define Flt_Rounds 1
3541181b21fSPeter Avalos #endif
3551181b21fSPeter Avalos #endif /*Flt_Rounds*/
3561181b21fSPeter Avalos 
3571181b21fSPeter Avalos #else /* ifndef IEEE_Arith */
3581181b21fSPeter Avalos #undef  Sudden_Underflow
3591181b21fSPeter Avalos #define Sudden_Underflow
3601181b21fSPeter Avalos #ifdef IBM
3611181b21fSPeter Avalos #undef Flt_Rounds
3621181b21fSPeter Avalos #define Flt_Rounds 0
3631181b21fSPeter Avalos #define Exp_shift  24
3641181b21fSPeter Avalos #define Exp_shift1 24
3651181b21fSPeter Avalos #define Exp_msk1   0x1000000
3661181b21fSPeter Avalos #define Exp_msk11  0x1000000
3671181b21fSPeter Avalos #define Exp_mask  0x7f000000
3681181b21fSPeter Avalos #define P 14
3691181b21fSPeter Avalos #define Bias 65
3701181b21fSPeter Avalos #define Exp_1  0x41000000
3711181b21fSPeter Avalos #define Exp_11 0x41000000
3721181b21fSPeter Avalos #define Ebits 8	/* exponent has 7 bits, but 8 is the right value in b2d */
3731181b21fSPeter Avalos #define Frac_mask  0xffffff
3741181b21fSPeter Avalos #define Frac_mask1 0xffffff
3751181b21fSPeter Avalos #define Bletch 4
3761181b21fSPeter Avalos #define Ten_pmax 22
3771181b21fSPeter Avalos #define Bndry_mask  0xefffff
3781181b21fSPeter Avalos #define Bndry_mask1 0xffffff
3791181b21fSPeter Avalos #define LSB 1
3801181b21fSPeter Avalos #define Sign_bit 0x80000000
3811181b21fSPeter Avalos #define Log2P 4
3821181b21fSPeter Avalos #define Tiny0 0x100000
3831181b21fSPeter Avalos #define Tiny1 0
3841181b21fSPeter Avalos #define Quick_max 14
3851181b21fSPeter Avalos #define Int_max 15
3861181b21fSPeter Avalos #else /* VAX */
3871181b21fSPeter Avalos #undef Flt_Rounds
3881181b21fSPeter Avalos #define Flt_Rounds 1
3891181b21fSPeter Avalos #define Exp_shift  23
3901181b21fSPeter Avalos #define Exp_shift1 7
3911181b21fSPeter Avalos #define Exp_msk1    0x80
3921181b21fSPeter Avalos #define Exp_msk11   0x800000
3931181b21fSPeter Avalos #define Exp_mask  0x7f80
3941181b21fSPeter Avalos #define P 56
3951181b21fSPeter Avalos #define Bias 129
3961181b21fSPeter Avalos #define Exp_1  0x40800000
3971181b21fSPeter Avalos #define Exp_11 0x4080
3981181b21fSPeter Avalos #define Ebits 8
3991181b21fSPeter Avalos #define Frac_mask  0x7fffff
4001181b21fSPeter Avalos #define Frac_mask1 0xffff007f
4011181b21fSPeter Avalos #define Ten_pmax 24
4021181b21fSPeter Avalos #define Bletch 2
4031181b21fSPeter Avalos #define Bndry_mask  0xffff007f
4041181b21fSPeter Avalos #define Bndry_mask1 0xffff007f
4051181b21fSPeter Avalos #define LSB 0x10000
4061181b21fSPeter Avalos #define Sign_bit 0x8000
4071181b21fSPeter Avalos #define Log2P 1
4081181b21fSPeter Avalos #define Tiny0 0x80
4091181b21fSPeter Avalos #define Tiny1 0
4101181b21fSPeter Avalos #define Quick_max 15
4111181b21fSPeter Avalos #define Int_max 15
4121181b21fSPeter Avalos #endif /* IBM, VAX */
4131181b21fSPeter Avalos #endif /* IEEE_Arith */
4141181b21fSPeter Avalos 
4151181b21fSPeter Avalos #ifndef IEEE_Arith
4161181b21fSPeter Avalos #define ROUND_BIASED
417ba7b3c3cSPeter Avalos #else
418ba7b3c3cSPeter Avalos #ifdef ROUND_BIASED_without_Round_Up
419ba7b3c3cSPeter Avalos #undef  ROUND_BIASED
420ba7b3c3cSPeter Avalos #define ROUND_BIASED
421ba7b3c3cSPeter Avalos #endif
4221181b21fSPeter Avalos #endif
4231181b21fSPeter Avalos 
4241181b21fSPeter Avalos #ifdef RND_PRODQUOT
4251181b21fSPeter Avalos #define rounded_product(a,b) a = rnd_prod(a, b)
4261181b21fSPeter Avalos #define rounded_quotient(a,b) a = rnd_quot(a, b)
4271181b21fSPeter Avalos #ifdef KR_headers
4281181b21fSPeter Avalos extern double rnd_prod(), rnd_quot();
4291181b21fSPeter Avalos #else
4301181b21fSPeter Avalos extern double rnd_prod(double, double), rnd_quot(double, double);
4311181b21fSPeter Avalos #endif
4321181b21fSPeter Avalos #else
4331181b21fSPeter Avalos #define rounded_product(a,b) a *= b
4341181b21fSPeter Avalos #define rounded_quotient(a,b) a /= b
4351181b21fSPeter Avalos #endif
4361181b21fSPeter Avalos 
4371181b21fSPeter Avalos #define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))
4381181b21fSPeter Avalos #define Big1 0xffffffff
4391181b21fSPeter Avalos 
4401181b21fSPeter Avalos #undef  Pack_16
4411181b21fSPeter Avalos #ifndef Pack_32
4421181b21fSPeter Avalos #define Pack_32
4431181b21fSPeter Avalos #endif
4441181b21fSPeter Avalos 
4451181b21fSPeter Avalos #ifdef NO_LONG_LONG
4461181b21fSPeter Avalos #undef ULLong
4471181b21fSPeter Avalos #ifdef Just_16
4481181b21fSPeter Avalos #undef Pack_32
4491181b21fSPeter Avalos #define Pack_16
4501181b21fSPeter Avalos /* When Pack_32 is not defined, we store 16 bits per 32-bit Long.
4511181b21fSPeter Avalos  * This makes some inner loops simpler and sometimes saves work
4521181b21fSPeter Avalos  * during multiplications, but it often seems to make things slightly
4531181b21fSPeter Avalos  * slower.  Hence the default is now to store 32 bits per Long.
4541181b21fSPeter Avalos  */
4551181b21fSPeter Avalos #endif
4561181b21fSPeter Avalos #else	/* long long available */
4571181b21fSPeter Avalos #ifndef Llong
4581181b21fSPeter Avalos #define Llong long long
4591181b21fSPeter Avalos #endif
4601181b21fSPeter Avalos #ifndef ULLong
4611181b21fSPeter Avalos #define ULLong unsigned Llong
4621181b21fSPeter Avalos #endif
4631181b21fSPeter Avalos #endif /* NO_LONG_LONG */
4641181b21fSPeter Avalos 
4651181b21fSPeter Avalos #ifdef Pack_32
4661181b21fSPeter Avalos #define ULbits 32
4671181b21fSPeter Avalos #define kshift 5
4681181b21fSPeter Avalos #define kmask 31
4691181b21fSPeter Avalos #define ALL_ON 0xffffffff
4701181b21fSPeter Avalos #else
4711181b21fSPeter Avalos #define ULbits 16
4721181b21fSPeter Avalos #define kshift 4
4731181b21fSPeter Avalos #define kmask 15
4741181b21fSPeter Avalos #define ALL_ON 0xffff
4751181b21fSPeter Avalos #endif
4761181b21fSPeter Avalos 
4776c3587b9SPeter Avalos #define MULTIPLE_THREADS
4786c3587b9SPeter Avalos extern pthread_mutex_t __gdtoa_locks[2];
4796c3587b9SPeter Avalos #define ACQUIRE_DTOA_LOCK(n)	do {				\
4806c3587b9SPeter Avalos 	if (__isthreaded)					\
4816c3587b9SPeter Avalos 		_pthread_mutex_lock(&__gdtoa_locks[n]);		\
4826c3587b9SPeter Avalos } while(0)
4836c3587b9SPeter Avalos #define FREE_DTOA_LOCK(n)	do {				\
4846c3587b9SPeter Avalos 	if (__isthreaded)					\
4856c3587b9SPeter Avalos 		_pthread_mutex_unlock(&__gdtoa_locks[n]);	\
4866c3587b9SPeter Avalos } while(0)
4871181b21fSPeter Avalos 
4882a5b511eSPeter Avalos #define Kmax 9
4891181b21fSPeter Avalos 
4901181b21fSPeter Avalos  struct
4911181b21fSPeter Avalos Bigint {
4921181b21fSPeter Avalos 	struct Bigint *next;
4931181b21fSPeter Avalos 	int k, maxwds, sign, wds;
4941181b21fSPeter Avalos 	ULong x[1];
4951181b21fSPeter Avalos 	};
4961181b21fSPeter Avalos 
4971181b21fSPeter Avalos  typedef struct Bigint Bigint;
4981181b21fSPeter Avalos 
4991181b21fSPeter Avalos #ifdef NO_STRING_H
5001181b21fSPeter Avalos #ifdef DECLARE_SIZE_T
5011181b21fSPeter Avalos typedef unsigned int size_t;
5021181b21fSPeter Avalos #endif
5031181b21fSPeter Avalos extern void memcpy_D2A ANSI((void*, const void*, size_t));
5041181b21fSPeter Avalos #define Bcopy(x,y) memcpy_D2A(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int))
5051181b21fSPeter Avalos #else /* !NO_STRING_H */
5061181b21fSPeter Avalos #define Bcopy(x,y) memcpy(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int))
5071181b21fSPeter Avalos #endif /* NO_STRING_H */
5081181b21fSPeter Avalos 
5096c3587b9SPeter Avalos /*
5106c3587b9SPeter Avalos  * Paranoia: Protect exported symbols, including ones in files we don't
5116c3587b9SPeter Avalos  * compile right now.  The standard strtof and strtod survive.
5126c3587b9SPeter Avalos  */
5136c3587b9SPeter Avalos #define	dtoa		__dtoa
5146c3587b9SPeter Avalos #define	gdtoa		__gdtoa
5156c3587b9SPeter Avalos #define	freedtoa	__freedtoa
5166c3587b9SPeter Avalos #define	strtodg		__strtodg
5176c3587b9SPeter Avalos #define	g_ddfmt		__g_ddfmt
5186c3587b9SPeter Avalos #define	g_dfmt		__g_dfmt
5196c3587b9SPeter Avalos #define	g_ffmt		__g_ffmt
5206c3587b9SPeter Avalos #define	g_Qfmt		__g_Qfmt
5216c3587b9SPeter Avalos #define	g_xfmt		__g_xfmt
5226c3587b9SPeter Avalos #define	g_xLfmt		__g_xLfmt
5236c3587b9SPeter Avalos #define	strtoId		__strtoId
5246c3587b9SPeter Avalos #define	strtoIdd	__strtoIdd
5256c3587b9SPeter Avalos #define	strtoIf		__strtoIf
5266c3587b9SPeter Avalos #define	strtoIQ		__strtoIQ
5276c3587b9SPeter Avalos #define	strtoIx		__strtoIx
5286c3587b9SPeter Avalos #define	strtoIxL	__strtoIxL
529*0d5acd74SJohn Marino #define	strtord_l		__strtord_l
5306c3587b9SPeter Avalos #define	strtordd	__strtordd
5316c3587b9SPeter Avalos #define	strtorf		__strtorf
532*0d5acd74SJohn Marino #define	strtorQ_l		__strtorQ_l
533*0d5acd74SJohn Marino #define	strtorx_l		__strtorx_l
5346c3587b9SPeter Avalos #define	strtorxL	__strtorxL
5356c3587b9SPeter Avalos #define	strtodI		__strtodI
5366c3587b9SPeter Avalos #define	strtopd		__strtopd
5376c3587b9SPeter Avalos #define	strtopdd	__strtopdd
5386c3587b9SPeter Avalos #define	strtopf		__strtopf
5396c3587b9SPeter Avalos #define	strtopQ		__strtopQ
5406c3587b9SPeter Avalos #define	strtopx		__strtopx
5416c3587b9SPeter Avalos #define	strtopxL	__strtopxL
5426c3587b9SPeter Avalos 
5436c3587b9SPeter Avalos /* Protect gdtoa-internal symbols */
5446c3587b9SPeter Avalos #define	Balloc		__Balloc_D2A
5456c3587b9SPeter Avalos #define	Bfree		__Bfree_D2A
5466c3587b9SPeter Avalos #define	ULtoQ		__ULtoQ_D2A
5476c3587b9SPeter Avalos #define	ULtof		__ULtof_D2A
5486c3587b9SPeter Avalos #define	ULtod		__ULtod_D2A
5496c3587b9SPeter Avalos #define	ULtodd		__ULtodd_D2A
5506c3587b9SPeter Avalos #define	ULtox		__ULtox_D2A
5516c3587b9SPeter Avalos #define	ULtoxL		__ULtoxL_D2A
5526c3587b9SPeter Avalos #define	any_on		__any_on_D2A
5536c3587b9SPeter Avalos #define	b2d		__b2d_D2A
5546c3587b9SPeter Avalos #define	bigtens		__bigtens_D2A
5556c3587b9SPeter Avalos #define	cmp		__cmp_D2A
5566c3587b9SPeter Avalos #define	copybits	__copybits_D2A
5576c3587b9SPeter Avalos #define	d2b		__d2b_D2A
5586c3587b9SPeter Avalos #define	decrement	__decrement_D2A
5596c3587b9SPeter Avalos #define	diff		__diff_D2A
5606c3587b9SPeter Avalos #define	dtoa_result	__dtoa_result_D2A
5616c3587b9SPeter Avalos #define	g__fmt		__g__fmt_D2A
5626c3587b9SPeter Avalos #define	gethex		__gethex_D2A
5636c3587b9SPeter Avalos #define	hexdig		__hexdig_D2A
5646c3587b9SPeter Avalos #define	hexdig_init_D2A	__hexdig_init_D2A
5656c3587b9SPeter Avalos #define	hexnan		__hexnan_D2A
566*0d5acd74SJohn Marino #define	hi0bits		__hi0bits_D2A
5676c3587b9SPeter Avalos #define	hi0bits_D2A	__hi0bits_D2A
5686c3587b9SPeter Avalos #define	i2b		__i2b_D2A
5696c3587b9SPeter Avalos #define	increment	__increment_D2A
5706c3587b9SPeter Avalos #define	lo0bits		__lo0bits_D2A
5716c3587b9SPeter Avalos #define	lshift		__lshift_D2A
5726c3587b9SPeter Avalos #define	match		__match_D2A
5736c3587b9SPeter Avalos #define	mult		__mult_D2A
5746c3587b9SPeter Avalos #define	multadd		__multadd_D2A
5756c3587b9SPeter Avalos #define	nrv_alloc	__nrv_alloc_D2A
5766c3587b9SPeter Avalos #define	pow5mult	__pow5mult_D2A
5776c3587b9SPeter Avalos #define	quorem		__quorem_D2A
5786c3587b9SPeter Avalos #define	ratio		__ratio_D2A
5796c3587b9SPeter Avalos #define	rshift		__rshift_D2A
5806c3587b9SPeter Avalos #define	rv_alloc	__rv_alloc_D2A
5816c3587b9SPeter Avalos #define	s2b		__s2b_D2A
5826c3587b9SPeter Avalos #define	set_ones	__set_ones_D2A
5836c3587b9SPeter Avalos #define	strcp		__strcp_D2A
5846c3587b9SPeter Avalos #define	strcp_D2A      	__strcp_D2A
5856c3587b9SPeter Avalos #define	strtoIg		__strtoIg_D2A
5866c3587b9SPeter Avalos #define	sum		__sum_D2A
5876c3587b9SPeter Avalos #define	tens		__tens_D2A
5886c3587b9SPeter Avalos #define	tinytens	__tinytens_D2A
5896c3587b9SPeter Avalos #define	tinytens	__tinytens_D2A
5906c3587b9SPeter Avalos #define	trailz		__trailz_D2A
5916c3587b9SPeter Avalos #define	ulp		__ulp_D2A
5921181b21fSPeter Avalos 
5931181b21fSPeter Avalos  extern char *dtoa_result;
5941181b21fSPeter Avalos  extern CONST double bigtens[], tens[], tinytens[];
5951181b21fSPeter Avalos  extern unsigned char hexdig[];
5961181b21fSPeter Avalos 
5971181b21fSPeter Avalos  extern Bigint *Balloc ANSI((int));
5981181b21fSPeter Avalos  extern void Bfree ANSI((Bigint*));
5991181b21fSPeter Avalos  extern void ULtof ANSI((ULong*, ULong*, Long, int));
6001181b21fSPeter Avalos  extern void ULtod ANSI((ULong*, ULong*, Long, int));
6011181b21fSPeter Avalos  extern void ULtodd ANSI((ULong*, ULong*, Long, int));
6021181b21fSPeter Avalos  extern void ULtoQ ANSI((ULong*, ULong*, Long, int));
6031181b21fSPeter Avalos  extern void ULtox ANSI((UShort*, ULong*, Long, int));
6041181b21fSPeter Avalos  extern void ULtoxL ANSI((ULong*, ULong*, Long, int));
6051181b21fSPeter Avalos  extern ULong any_on ANSI((Bigint*, int));
6061181b21fSPeter Avalos  extern double b2d ANSI((Bigint*, int*));
6071181b21fSPeter Avalos  extern int cmp ANSI((Bigint*, Bigint*));
6081181b21fSPeter Avalos  extern void copybits ANSI((ULong*, int, Bigint*));
6091181b21fSPeter Avalos  extern Bigint *d2b ANSI((double, int*, int*));
6101181b21fSPeter Avalos  extern void decrement ANSI((Bigint*));
6111181b21fSPeter Avalos  extern Bigint *diff ANSI((Bigint*, Bigint*));
6121181b21fSPeter Avalos  extern char *dtoa ANSI((double d, int mode, int ndigits,
6131181b21fSPeter Avalos 			int *decpt, int *sign, char **rve));
6146c3587b9SPeter Avalos  extern void freedtoa ANSI((char*));
6156c3587b9SPeter Avalos  extern char *gdtoa ANSI((FPI *fpi, int be, ULong *bits, int *kindp,
6166c3587b9SPeter Avalos 			  int mode, int ndigits, int *decpt, char **rve));
617*0d5acd74SJohn Marino  extern char *g__fmt ANSI((char*, char*, char*, int, ULong, size_t));
6181181b21fSPeter Avalos  extern int gethex ANSI((CONST char**, FPI*, Long*, Bigint**, int));
6191181b21fSPeter Avalos  extern void hexdig_init_D2A(Void);
6201181b21fSPeter Avalos  extern int hexnan ANSI((CONST char**, FPI*, ULong*));
621*0d5acd74SJohn Marino  extern int hi0bits ANSI((ULong));
6221181b21fSPeter Avalos  extern Bigint *i2b ANSI((int));
6231181b21fSPeter Avalos  extern Bigint *increment ANSI((Bigint*));
6241181b21fSPeter Avalos  extern int lo0bits ANSI((ULong*));
6251181b21fSPeter Avalos  extern Bigint *lshift ANSI((Bigint*, int));
6261181b21fSPeter Avalos  extern int match ANSI((CONST char**, char*));
6271181b21fSPeter Avalos  extern Bigint *mult ANSI((Bigint*, Bigint*));
6281181b21fSPeter Avalos  extern Bigint *multadd ANSI((Bigint*, int, int));
6291181b21fSPeter Avalos  extern char *nrv_alloc ANSI((char*, char **, int));
6301181b21fSPeter Avalos  extern Bigint *pow5mult ANSI((Bigint*, int));
6311181b21fSPeter Avalos  extern int quorem ANSI((Bigint*, Bigint*));
6321181b21fSPeter Avalos  extern double ratio ANSI((Bigint*, Bigint*));
6331181b21fSPeter Avalos  extern void rshift ANSI((Bigint*, int));
6341181b21fSPeter Avalos  extern char *rv_alloc ANSI((int));
6351181b21fSPeter Avalos  extern Bigint *s2b ANSI((CONST char*, int, int, ULong, int));
6361181b21fSPeter Avalos  extern Bigint *set_ones ANSI((Bigint*, int));
6371181b21fSPeter Avalos  extern char *strcp ANSI((char*, const char*));
638*0d5acd74SJohn Marino  extern int strtodg_l ANSI((CONST char*, char**, FPI*, Long*, ULong*, locale_t));
6396c3587b9SPeter Avalos 
6406c3587b9SPeter Avalos  extern int strtoId ANSI((CONST char *, char **, double *, double *));
6416c3587b9SPeter Avalos  extern int strtoIdd ANSI((CONST char *, char **, double *, double *));
6426c3587b9SPeter Avalos  extern int strtoIf ANSI((CONST char *, char **, float *, float *));
6431181b21fSPeter Avalos  extern int strtoIg ANSI((CONST char*, char**, FPI*, Long*, Bigint**, int*));
6446c3587b9SPeter Avalos  extern int strtoIQ ANSI((CONST char *, char **, void *, void *));
6456c3587b9SPeter Avalos  extern int strtoIx ANSI((CONST char *, char **, void *, void *));
6466c3587b9SPeter Avalos  extern int strtoIxL ANSI((CONST char *, char **, void *, void *));
6471181b21fSPeter Avalos  extern double strtod ANSI((const char *s00, char **se));
648*0d5acd74SJohn Marino  extern double strtod_l ANSI((const char *s00, char **se, locale_t));
6496c3587b9SPeter Avalos  extern int strtopQ ANSI((CONST char *, char **, Void *));
6506c3587b9SPeter Avalos  extern int strtopf ANSI((CONST char *, char **, float *));
6516c3587b9SPeter Avalos  extern int strtopd ANSI((CONST char *, char **, double *));
6526c3587b9SPeter Avalos  extern int strtopdd ANSI((CONST char *, char **, double *));
6536c3587b9SPeter Avalos  extern int strtopx ANSI((CONST char *, char **, Void *));
6546c3587b9SPeter Avalos  extern int strtopxL ANSI((CONST char *, char **, Void *));
655*0d5acd74SJohn Marino  extern int strtord_l ANSI((CONST char *, char **, int, double *, locale_t));
6566c3587b9SPeter Avalos  extern int strtordd ANSI((CONST char *, char **, int, double *));
6576c3587b9SPeter Avalos  extern int strtorf ANSI((CONST char *, char **, int, float *));
658*0d5acd74SJohn Marino  extern int strtorQ_l ANSI((CONST char *, char **, int, void *, locale_t));
659*0d5acd74SJohn Marino  extern int strtorx_l ANSI((CONST char *, char **, int, void *, locale_t));
6606c3587b9SPeter Avalos  extern int strtorxL ANSI((CONST char *, char **, int, void *));
6611181b21fSPeter Avalos  extern Bigint *sum ANSI((Bigint*, Bigint*));
6621181b21fSPeter Avalos  extern int trailz ANSI((Bigint*));
6632a5b511eSPeter Avalos  extern double ulp ANSI((U*));
6641181b21fSPeter Avalos 
6651181b21fSPeter Avalos #ifdef __cplusplus
6661181b21fSPeter Avalos }
6671181b21fSPeter Avalos #endif
6681181b21fSPeter Avalos /*
6691181b21fSPeter Avalos  * NAN_WORD0 and NAN_WORD1 are only referenced in strtod.c.  Prior to
6701181b21fSPeter Avalos  * 20050115, they used to be hard-wired here (to 0x7ff80000 and 0,
6711181b21fSPeter Avalos  * respectively), but now are determined by compiling and running
6721181b21fSPeter Avalos  * qnan.c to generate gd_qnan.h, which specifies d_QNAN0 and d_QNAN1.
6731181b21fSPeter Avalos  * Formerly gdtoaimp.h recommended supplying suitable -DNAN_WORD0=...
6741181b21fSPeter Avalos  * and -DNAN_WORD1=...  values if necessary.  This should still work.
6751181b21fSPeter Avalos  * (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.)
6761181b21fSPeter Avalos  */
6771181b21fSPeter Avalos #ifdef IEEE_Arith
6781181b21fSPeter Avalos #ifndef NO_INFNAN_CHECK
6791181b21fSPeter Avalos #undef INFNAN_CHECK
6801181b21fSPeter Avalos #define INFNAN_CHECK
6811181b21fSPeter Avalos #endif
6821181b21fSPeter Avalos #ifdef IEEE_MC68k
6831181b21fSPeter Avalos #define _0 0
6841181b21fSPeter Avalos #define _1 1
6851181b21fSPeter Avalos #ifndef NAN_WORD0
6861181b21fSPeter Avalos #define NAN_WORD0 d_QNAN0
6871181b21fSPeter Avalos #endif
6881181b21fSPeter Avalos #ifndef NAN_WORD1
6891181b21fSPeter Avalos #define NAN_WORD1 d_QNAN1
6901181b21fSPeter Avalos #endif
6911181b21fSPeter Avalos #else
6921181b21fSPeter Avalos #define _0 1
6931181b21fSPeter Avalos #define _1 0
6941181b21fSPeter Avalos #ifndef NAN_WORD0
6951181b21fSPeter Avalos #define NAN_WORD0 d_QNAN1
6961181b21fSPeter Avalos #endif
6971181b21fSPeter Avalos #ifndef NAN_WORD1
6981181b21fSPeter Avalos #define NAN_WORD1 d_QNAN0
6991181b21fSPeter Avalos #endif
7001181b21fSPeter Avalos #endif
7011181b21fSPeter Avalos #else
7021181b21fSPeter Avalos #undef INFNAN_CHECK
7031181b21fSPeter Avalos #endif
7041181b21fSPeter Avalos 
7051181b21fSPeter Avalos #undef SI
7061181b21fSPeter Avalos #ifdef Sudden_Underflow
7071181b21fSPeter Avalos #define SI 1
7081181b21fSPeter Avalos #else
7091181b21fSPeter Avalos #define SI 0
7101181b21fSPeter Avalos #endif
7111181b21fSPeter Avalos 
7121181b21fSPeter Avalos #endif /* GDTOAIMP_H_INCLUDED */
713