xref: /freebsd/contrib/gdtoa/gdtoaimp.h (revision 8fa0b743820f61c661ba5f3ea0e3be0dc137910e)
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.
9950dad48bSDavid Schultz  * #define ROUND_BIASED for IEEE-format with biased rounding and arithmetic
10050dad48bSDavid Schultz  *	that rounds toward +Infinity.
10150dad48bSDavid Schultz  * #define ROUND_BIASED_without_Round_Up for IEEE-format with biased
10250dad48bSDavid Schultz  *	rounding when the underlying floating-point arithmetic uses
10350dad48bSDavid Schultz  *	unbiased rounding.  This prevent using ordinary floating-point
10450dad48bSDavid Schultz  *	arithmetic when the result could be computed with one rounding error.
105cc36ccd1SDavid Schultz  * #define Inaccurate_Divide for IEEE-format with correctly rounded
106cc36ccd1SDavid Schultz  *	products but inaccurate quotients, e.g., for Intel i860.
107cc36ccd1SDavid Schultz  * #define NO_LONG_LONG on machines that do not have a "long long"
108cc36ccd1SDavid Schultz  *	integer type (of >= 64 bits).  On such machines, you can
109cc36ccd1SDavid Schultz  *	#define Just_16 to store 16 bits per 32-bit Long when doing
110cc36ccd1SDavid Schultz  *	high-precision integer arithmetic.  Whether this speeds things
111cc36ccd1SDavid Schultz  *	up or slows things down depends on the machine and the number
112cc36ccd1SDavid Schultz  *	being converted.  If long long is available and the name is
113cc36ccd1SDavid Schultz  *	something other than "long long", #define Llong to be the name,
114cc36ccd1SDavid Schultz  *	and if "unsigned Llong" does not work as an unsigned version of
115cc36ccd1SDavid Schultz  *	Llong, #define #ULLong to be the corresponding unsigned type.
116cc36ccd1SDavid Schultz  * #define KR_headers for old-style C function headers.
117cc36ccd1SDavid Schultz  * #define Bad_float_h if your system lacks a float.h or if it does not
118cc36ccd1SDavid Schultz  *	define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP,
119cc36ccd1SDavid Schultz  *	FLT_RADIX, FLT_ROUNDS, and DBL_MAX.
120cc36ccd1SDavid Schultz  * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n)
121cc36ccd1SDavid Schultz  *	if memory is available and otherwise does something you deem
122cc36ccd1SDavid Schultz  *	appropriate.  If MALLOC is undefined, malloc will be invoked
12350dad48bSDavid Schultz  *	directly -- and assumed always to succeed.  Similarly, if you
12450dad48bSDavid Schultz  *	want something other than the system's free() to be called to
12550dad48bSDavid Schultz  *	recycle memory acquired from MALLOC, #define FREE to be the
12650dad48bSDavid Schultz  *	name of the alternate routine.  (FREE or free is only called in
12750dad48bSDavid Schultz  *	pathological cases, e.g., in a gdtoa call after a gdtoa return in
12850dad48bSDavid Schultz  *	mode 3 with thousands of digits requested.)
129cc36ccd1SDavid Schultz  * #define Omit_Private_Memory to omit logic (added Jan. 1998) for making
130cc36ccd1SDavid Schultz  *	memory allocations from a private pool of memory when possible.
131cc36ccd1SDavid Schultz  *	When used, the private pool is PRIVATE_MEM bytes long:  2304 bytes,
132cc36ccd1SDavid Schultz  *	unless #defined to be a different length.  This default length
133cc36ccd1SDavid Schultz  *	suffices to get rid of MALLOC calls except for unusual cases,
134cc36ccd1SDavid Schultz  *	such as decimal-to-binary conversion of a very long string of
135cc36ccd1SDavid Schultz  *	digits.  When converting IEEE double precision values, the
136cc36ccd1SDavid Schultz  *	longest string gdtoa can return is about 751 bytes long.  For
137cc36ccd1SDavid Schultz  *	conversions by strtod of strings of 800 digits and all gdtoa
138cc36ccd1SDavid Schultz  *	conversions of IEEE doubles in single-threaded executions with
139cc36ccd1SDavid Schultz  *	8-byte pointers, PRIVATE_MEM >= 7400 appears to suffice; with
140cc36ccd1SDavid Schultz  *	4-byte pointers, PRIVATE_MEM >= 7112 appears adequate.
1414848dd08SDavid Schultz  * #define NO_INFNAN_CHECK if you do not wish to have INFNAN_CHECK
1424848dd08SDavid Schultz  *	#defined automatically on IEEE systems.  On such systems,
1434848dd08SDavid Schultz  *	when INFNAN_CHECK is #defined, strtod checks
1444848dd08SDavid Schultz  *	for Infinity and NaN (case insensitively).
145cc36ccd1SDavid Schultz  *	When INFNAN_CHECK is #defined and No_Hex_NaN is not #defined,
146cc36ccd1SDavid Schultz  *	strtodg also accepts (case insensitively) strings of the form
147ae2cbf4cSDavid Schultz  *	NaN(x), where x is a string of hexadecimal digits (optionally
148ae2cbf4cSDavid Schultz  *	preceded by 0x or 0X) and spaces; if there is only one string
149ae2cbf4cSDavid Schultz  *	of hexadecimal digits, it is taken for the fraction bits of the
150ae2cbf4cSDavid Schultz  *	resulting NaN; if there are two or more strings of hexadecimal
151ae2cbf4cSDavid Schultz  *	digits, each string is assigned to the next available sequence
152ae2cbf4cSDavid Schultz  *	of 32-bit words of fractions bits (starting with the most
153ae2cbf4cSDavid Schultz  *	significant), right-aligned in each sequence.
154ae2cbf4cSDavid Schultz  *	Unless GDTOA_NON_PEDANTIC_NANCHECK is #defined, input "NaN(...)"
155ae2cbf4cSDavid Schultz  *	is consumed even when ... has the wrong form (in which case the
156ae2cbf4cSDavid Schultz  *	"(...)" is consumed but ignored).
157cc36ccd1SDavid Schultz  * #define MULTIPLE_THREADS if the system offers preemptively scheduled
158cc36ccd1SDavid Schultz  *	multiple threads.  In this case, you must provide (or suitably
159cc36ccd1SDavid Schultz  *	#define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed
160cc36ccd1SDavid Schultz  *	by FREE_DTOA_LOCK(n) for n = 0 or 1.  (The second lock, accessed
161cc36ccd1SDavid Schultz  *	in pow5mult, ensures lazy evaluation of only one copy of high
162cc36ccd1SDavid Schultz  *	powers of 5; omitting this lock would introduce a small
163cc36ccd1SDavid Schultz  *	probability of wasting memory, but would otherwise be harmless.)
164cc36ccd1SDavid Schultz  *	You must also invoke freedtoa(s) to free the value s returned by
165cc36ccd1SDavid Schultz  *	dtoa.  You may do so whether or not MULTIPLE_THREADS is #defined.
166cc36ccd1SDavid Schultz  * #define IMPRECISE_INEXACT if you do not care about the setting of
167cc36ccd1SDavid Schultz  *	the STRTOG_Inexact bits in the special case of doing IEEE double
168ae2cbf4cSDavid Schultz  *	precision conversions (which could also be done by the strtod in
169cc36ccd1SDavid Schultz  *	dtoa.c).
170cc36ccd1SDavid Schultz  * #define NO_HEX_FP to disable recognition of C9x's hexadecimal
171cc36ccd1SDavid Schultz  *	floating-point constants.
172cc36ccd1SDavid Schultz  * #define -DNO_ERRNO to suppress setting errno (in strtod.c and
173cc36ccd1SDavid Schultz  *	strtodg.c).
174cc36ccd1SDavid Schultz  * #define NO_STRING_H to use private versions of memcpy.
175cc36ccd1SDavid Schultz  *	On some K&R systems, it may also be necessary to
176cc36ccd1SDavid Schultz  *	#define DECLARE_SIZE_T in this case.
177cc36ccd1SDavid Schultz  * #define USE_LOCALE to use the current locale's decimal_point value.
178cc36ccd1SDavid Schultz  */
179cc36ccd1SDavid Schultz 
180cc36ccd1SDavid Schultz #ifndef GDTOAIMP_H_INCLUDED
181cc36ccd1SDavid Schultz #define GDTOAIMP_H_INCLUDED
1829cb41668SDavid Schultz 
1839cb41668SDavid Schultz #define	Long	int
1849cb41668SDavid Schultz 
185cc36ccd1SDavid Schultz #include "gdtoa.h"
18627314703SDavid Schultz #include "gd_qnan.h"
1874848dd08SDavid Schultz #ifdef Honor_FLT_ROUNDS
1884848dd08SDavid Schultz #include <fenv.h>
1894848dd08SDavid Schultz #endif
190cc36ccd1SDavid Schultz 
191cc36ccd1SDavid Schultz #ifdef DEBUG
192cc36ccd1SDavid Schultz #include "stdio.h"
193cc36ccd1SDavid Schultz #define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);}
194cc36ccd1SDavid Schultz #endif
195cc36ccd1SDavid Schultz 
196de9840c6SDavid Schultz #include "limits.h"
197cc36ccd1SDavid Schultz #include "stdlib.h"
198cc36ccd1SDavid Schultz #include "string.h"
199de9840c6SDavid Schultz #include "libc_private.h"
200d086ded3SDavid Schultz 
201d086ded3SDavid Schultz #include "namespace.h"
202d086ded3SDavid Schultz #include <pthread.h>
203d086ded3SDavid Schultz #include "un-namespace.h"
204*3c87aa1dSDavid Chisnall #include "xlocale_private.h"
205cc36ccd1SDavid Schultz 
206cc36ccd1SDavid Schultz #ifdef KR_headers
207cc36ccd1SDavid Schultz #define Char char
208cc36ccd1SDavid Schultz #else
209cc36ccd1SDavid Schultz #define Char void
210cc36ccd1SDavid Schultz #endif
211cc36ccd1SDavid Schultz 
212cc36ccd1SDavid Schultz #ifdef MALLOC
213cc36ccd1SDavid Schultz extern Char *MALLOC ANSI((size_t));
214cc36ccd1SDavid Schultz #else
215cc36ccd1SDavid Schultz #define MALLOC malloc
216cc36ccd1SDavid Schultz #endif
217cc36ccd1SDavid Schultz 
218de9840c6SDavid Schultz #define INFNAN_CHECK
2191dd3a3dbSDavid Schultz #define USE_LOCALE
2204848dd08SDavid Schultz #define NO_LOCALE_CACHE
221ba54cdcdSDavid Schultz #define Honor_FLT_ROUNDS
222ae2cbf4cSDavid Schultz #define Trust_FLT_ROUNDS
223de9840c6SDavid Schultz 
224cc36ccd1SDavid Schultz #undef IEEE_Arith
225cc36ccd1SDavid Schultz #undef Avoid_Underflow
226cc36ccd1SDavid Schultz #ifdef IEEE_MC68k
227cc36ccd1SDavid Schultz #define IEEE_Arith
228cc36ccd1SDavid Schultz #endif
229cc36ccd1SDavid Schultz #ifdef IEEE_8087
230cc36ccd1SDavid Schultz #define IEEE_Arith
231cc36ccd1SDavid Schultz #endif
232cc36ccd1SDavid Schultz 
233cc36ccd1SDavid Schultz #include "errno.h"
234cc36ccd1SDavid Schultz #ifdef Bad_float_h
235cc36ccd1SDavid Schultz 
236cc36ccd1SDavid Schultz #ifdef IEEE_Arith
237cc36ccd1SDavid Schultz #define DBL_DIG 15
238cc36ccd1SDavid Schultz #define DBL_MAX_10_EXP 308
239cc36ccd1SDavid Schultz #define DBL_MAX_EXP 1024
240cc36ccd1SDavid Schultz #define FLT_RADIX 2
241cc36ccd1SDavid Schultz #define DBL_MAX 1.7976931348623157e+308
242cc36ccd1SDavid Schultz #endif
243cc36ccd1SDavid Schultz 
244cc36ccd1SDavid Schultz #ifdef IBM
245cc36ccd1SDavid Schultz #define DBL_DIG 16
246cc36ccd1SDavid Schultz #define DBL_MAX_10_EXP 75
247cc36ccd1SDavid Schultz #define DBL_MAX_EXP 63
248cc36ccd1SDavid Schultz #define FLT_RADIX 16
249cc36ccd1SDavid Schultz #define DBL_MAX 7.2370055773322621e+75
250cc36ccd1SDavid Schultz #endif
251cc36ccd1SDavid Schultz 
252cc36ccd1SDavid Schultz #ifdef VAX
253cc36ccd1SDavid Schultz #define DBL_DIG 16
254cc36ccd1SDavid Schultz #define DBL_MAX_10_EXP 38
255cc36ccd1SDavid Schultz #define DBL_MAX_EXP 127
256cc36ccd1SDavid Schultz #define FLT_RADIX 2
257cc36ccd1SDavid Schultz #define DBL_MAX 1.7014118346046923e+38
258cc36ccd1SDavid Schultz #define n_bigtens 2
259cc36ccd1SDavid Schultz #endif
260cc36ccd1SDavid Schultz 
261cc36ccd1SDavid Schultz #ifndef LONG_MAX
262cc36ccd1SDavid Schultz #define LONG_MAX 2147483647
263cc36ccd1SDavid Schultz #endif
264cc36ccd1SDavid Schultz 
265cc36ccd1SDavid Schultz #else /* ifndef Bad_float_h */
266cc36ccd1SDavid Schultz #include "float.h"
267cc36ccd1SDavid Schultz #endif /* Bad_float_h */
268cc36ccd1SDavid Schultz 
269cc36ccd1SDavid Schultz #ifdef IEEE_Arith
270cc36ccd1SDavid Schultz #define Scale_Bit 0x10
271cc36ccd1SDavid Schultz #define n_bigtens 5
272cc36ccd1SDavid Schultz #endif
273cc36ccd1SDavid Schultz 
274cc36ccd1SDavid Schultz #ifdef IBM
275cc36ccd1SDavid Schultz #define n_bigtens 3
276cc36ccd1SDavid Schultz #endif
277cc36ccd1SDavid Schultz 
278cc36ccd1SDavid Schultz #ifdef VAX
279cc36ccd1SDavid Schultz #define n_bigtens 2
280cc36ccd1SDavid Schultz #endif
281cc36ccd1SDavid Schultz 
282cc36ccd1SDavid Schultz #ifndef __MATH_H__
283cc36ccd1SDavid Schultz #include "math.h"
284cc36ccd1SDavid Schultz #endif
285cc36ccd1SDavid Schultz 
286cc36ccd1SDavid Schultz #ifdef __cplusplus
287cc36ccd1SDavid Schultz extern "C" {
288cc36ccd1SDavid Schultz #endif
289cc36ccd1SDavid Schultz 
290cc36ccd1SDavid Schultz #if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1
291cc36ccd1SDavid Schultz Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined.
292cc36ccd1SDavid Schultz #endif
293cc36ccd1SDavid Schultz 
294cc36ccd1SDavid Schultz typedef union { double d; ULong L[2]; } U;
295cc36ccd1SDavid Schultz 
296cc36ccd1SDavid Schultz #ifdef IEEE_8087
29750dad48bSDavid Schultz #define word0(x) (x)->L[1]
29850dad48bSDavid Schultz #define word1(x) (x)->L[0]
299cc36ccd1SDavid Schultz #else
30050dad48bSDavid Schultz #define word0(x) (x)->L[0]
30150dad48bSDavid Schultz #define word1(x) (x)->L[1]
302cc36ccd1SDavid Schultz #endif
30350dad48bSDavid Schultz #define dval(x) (x)->d
304cc36ccd1SDavid Schultz 
305cc36ccd1SDavid Schultz /* The following definition of Storeinc is appropriate for MIPS processors.
306cc36ccd1SDavid Schultz  * An alternative that might be better on some machines is
307cc36ccd1SDavid Schultz  * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff)
308cc36ccd1SDavid Schultz  */
309cc36ccd1SDavid Schultz #if defined(IEEE_8087) + defined(VAX)
310cc36ccd1SDavid Schultz #define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \
311cc36ccd1SDavid Schultz ((unsigned short *)a)[0] = (unsigned short)c, a++)
312cc36ccd1SDavid Schultz #else
313cc36ccd1SDavid Schultz #define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \
314cc36ccd1SDavid Schultz ((unsigned short *)a)[1] = (unsigned short)c, a++)
315cc36ccd1SDavid Schultz #endif
316cc36ccd1SDavid Schultz 
317cc36ccd1SDavid Schultz /* #define P DBL_MANT_DIG */
318cc36ccd1SDavid Schultz /* Ten_pmax = floor(P*log(2)/log(5)) */
319cc36ccd1SDavid Schultz /* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */
320cc36ccd1SDavid Schultz /* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */
321cc36ccd1SDavid Schultz /* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */
322cc36ccd1SDavid Schultz 
323cc36ccd1SDavid Schultz #ifdef IEEE_Arith
324cc36ccd1SDavid Schultz #define Exp_shift  20
325cc36ccd1SDavid Schultz #define Exp_shift1 20
326cc36ccd1SDavid Schultz #define Exp_msk1    0x100000
327cc36ccd1SDavid Schultz #define Exp_msk11   0x100000
328cc36ccd1SDavid Schultz #define Exp_mask  0x7ff00000
329cc36ccd1SDavid Schultz #define P 53
330cc36ccd1SDavid Schultz #define Bias 1023
331cc36ccd1SDavid Schultz #define Emin (-1022)
332cc36ccd1SDavid Schultz #define Exp_1  0x3ff00000
333cc36ccd1SDavid Schultz #define Exp_11 0x3ff00000
334cc36ccd1SDavid Schultz #define Ebits 11
335cc36ccd1SDavid Schultz #define Frac_mask  0xfffff
336cc36ccd1SDavid Schultz #define Frac_mask1 0xfffff
337cc36ccd1SDavid Schultz #define Ten_pmax 22
338cc36ccd1SDavid Schultz #define Bletch 0x10
339cc36ccd1SDavid Schultz #define Bndry_mask  0xfffff
340cc36ccd1SDavid Schultz #define Bndry_mask1 0xfffff
341cc36ccd1SDavid Schultz #define LSB 1
342cc36ccd1SDavid Schultz #define Sign_bit 0x80000000
343cc36ccd1SDavid Schultz #define Log2P 1
344cc36ccd1SDavid Schultz #define Tiny0 0
345cc36ccd1SDavid Schultz #define Tiny1 1
346cc36ccd1SDavid Schultz #define Quick_max 14
347cc36ccd1SDavid Schultz #define Int_max 14
348cc36ccd1SDavid Schultz 
349cc36ccd1SDavid Schultz #ifndef Flt_Rounds
350cc36ccd1SDavid Schultz #ifdef FLT_ROUNDS
351cc36ccd1SDavid Schultz #define Flt_Rounds FLT_ROUNDS
352cc36ccd1SDavid Schultz #else
353cc36ccd1SDavid Schultz #define Flt_Rounds 1
354cc36ccd1SDavid Schultz #endif
355cc36ccd1SDavid Schultz #endif /*Flt_Rounds*/
356cc36ccd1SDavid Schultz 
357cc36ccd1SDavid Schultz #else /* ifndef IEEE_Arith */
358cc36ccd1SDavid Schultz #undef  Sudden_Underflow
359cc36ccd1SDavid Schultz #define Sudden_Underflow
360cc36ccd1SDavid Schultz #ifdef IBM
361cc36ccd1SDavid Schultz #undef Flt_Rounds
362cc36ccd1SDavid Schultz #define Flt_Rounds 0
363cc36ccd1SDavid Schultz #define Exp_shift  24
364cc36ccd1SDavid Schultz #define Exp_shift1 24
365cc36ccd1SDavid Schultz #define Exp_msk1   0x1000000
366cc36ccd1SDavid Schultz #define Exp_msk11  0x1000000
367cc36ccd1SDavid Schultz #define Exp_mask  0x7f000000
368cc36ccd1SDavid Schultz #define P 14
369cc36ccd1SDavid Schultz #define Bias 65
370cc36ccd1SDavid Schultz #define Exp_1  0x41000000
371cc36ccd1SDavid Schultz #define Exp_11 0x41000000
372cc36ccd1SDavid Schultz #define Ebits 8	/* exponent has 7 bits, but 8 is the right value in b2d */
373cc36ccd1SDavid Schultz #define Frac_mask  0xffffff
374cc36ccd1SDavid Schultz #define Frac_mask1 0xffffff
375cc36ccd1SDavid Schultz #define Bletch 4
376cc36ccd1SDavid Schultz #define Ten_pmax 22
377cc36ccd1SDavid Schultz #define Bndry_mask  0xefffff
378cc36ccd1SDavid Schultz #define Bndry_mask1 0xffffff
379cc36ccd1SDavid Schultz #define LSB 1
380cc36ccd1SDavid Schultz #define Sign_bit 0x80000000
381cc36ccd1SDavid Schultz #define Log2P 4
382cc36ccd1SDavid Schultz #define Tiny0 0x100000
383cc36ccd1SDavid Schultz #define Tiny1 0
384cc36ccd1SDavid Schultz #define Quick_max 14
385cc36ccd1SDavid Schultz #define Int_max 15
386cc36ccd1SDavid Schultz #else /* VAX */
387cc36ccd1SDavid Schultz #undef Flt_Rounds
388cc36ccd1SDavid Schultz #define Flt_Rounds 1
389cc36ccd1SDavid Schultz #define Exp_shift  23
390cc36ccd1SDavid Schultz #define Exp_shift1 7
391cc36ccd1SDavid Schultz #define Exp_msk1    0x80
392cc36ccd1SDavid Schultz #define Exp_msk11   0x800000
393cc36ccd1SDavid Schultz #define Exp_mask  0x7f80
394cc36ccd1SDavid Schultz #define P 56
395cc36ccd1SDavid Schultz #define Bias 129
396cc36ccd1SDavid Schultz #define Exp_1  0x40800000
397cc36ccd1SDavid Schultz #define Exp_11 0x4080
398cc36ccd1SDavid Schultz #define Ebits 8
399cc36ccd1SDavid Schultz #define Frac_mask  0x7fffff
400cc36ccd1SDavid Schultz #define Frac_mask1 0xffff007f
401cc36ccd1SDavid Schultz #define Ten_pmax 24
402cc36ccd1SDavid Schultz #define Bletch 2
403cc36ccd1SDavid Schultz #define Bndry_mask  0xffff007f
404cc36ccd1SDavid Schultz #define Bndry_mask1 0xffff007f
405cc36ccd1SDavid Schultz #define LSB 0x10000
406cc36ccd1SDavid Schultz #define Sign_bit 0x8000
407cc36ccd1SDavid Schultz #define Log2P 1
408cc36ccd1SDavid Schultz #define Tiny0 0x80
409cc36ccd1SDavid Schultz #define Tiny1 0
410cc36ccd1SDavid Schultz #define Quick_max 15
411cc36ccd1SDavid Schultz #define Int_max 15
412cc36ccd1SDavid Schultz #endif /* IBM, VAX */
413cc36ccd1SDavid Schultz #endif /* IEEE_Arith */
414cc36ccd1SDavid Schultz 
415cc36ccd1SDavid Schultz #ifndef IEEE_Arith
416cc36ccd1SDavid Schultz #define ROUND_BIASED
41750dad48bSDavid Schultz #else
41850dad48bSDavid Schultz #ifdef ROUND_BIASED_without_Round_Up
41950dad48bSDavid Schultz #undef  ROUND_BIASED
42050dad48bSDavid Schultz #define ROUND_BIASED
42150dad48bSDavid Schultz #endif
422cc36ccd1SDavid Schultz #endif
423cc36ccd1SDavid Schultz 
424cc36ccd1SDavid Schultz #ifdef RND_PRODQUOT
425cc36ccd1SDavid Schultz #define rounded_product(a,b) a = rnd_prod(a, b)
426cc36ccd1SDavid Schultz #define rounded_quotient(a,b) a = rnd_quot(a, b)
427cc36ccd1SDavid Schultz #ifdef KR_headers
428cc36ccd1SDavid Schultz extern double rnd_prod(), rnd_quot();
429cc36ccd1SDavid Schultz #else
430cc36ccd1SDavid Schultz extern double rnd_prod(double, double), rnd_quot(double, double);
431cc36ccd1SDavid Schultz #endif
432cc36ccd1SDavid Schultz #else
433cc36ccd1SDavid Schultz #define rounded_product(a,b) a *= b
434cc36ccd1SDavid Schultz #define rounded_quotient(a,b) a /= b
435cc36ccd1SDavid Schultz #endif
436cc36ccd1SDavid Schultz 
437cc36ccd1SDavid Schultz #define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))
438cc36ccd1SDavid Schultz #define Big1 0xffffffff
439cc36ccd1SDavid Schultz 
440cc36ccd1SDavid Schultz #undef  Pack_16
441cc36ccd1SDavid Schultz #ifndef Pack_32
442cc36ccd1SDavid Schultz #define Pack_32
443cc36ccd1SDavid Schultz #endif
444cc36ccd1SDavid Schultz 
445cc36ccd1SDavid Schultz #ifdef NO_LONG_LONG
446cc36ccd1SDavid Schultz #undef ULLong
447cc36ccd1SDavid Schultz #ifdef Just_16
448cc36ccd1SDavid Schultz #undef Pack_32
449cc36ccd1SDavid Schultz #define Pack_16
450cc36ccd1SDavid Schultz /* When Pack_32 is not defined, we store 16 bits per 32-bit Long.
451cc36ccd1SDavid Schultz  * This makes some inner loops simpler and sometimes saves work
452cc36ccd1SDavid Schultz  * during multiplications, but it often seems to make things slightly
453cc36ccd1SDavid Schultz  * slower.  Hence the default is now to store 32 bits per Long.
454cc36ccd1SDavid Schultz  */
455cc36ccd1SDavid Schultz #endif
456cc36ccd1SDavid Schultz #else	/* long long available */
457cc36ccd1SDavid Schultz #ifndef Llong
458cc36ccd1SDavid Schultz #define Llong long long
459cc36ccd1SDavid Schultz #endif
460cc36ccd1SDavid Schultz #ifndef ULLong
461cc36ccd1SDavid Schultz #define ULLong unsigned Llong
462cc36ccd1SDavid Schultz #endif
463cc36ccd1SDavid Schultz #endif /* NO_LONG_LONG */
464cc36ccd1SDavid Schultz 
465cc36ccd1SDavid Schultz #ifdef Pack_32
466cc36ccd1SDavid Schultz #define ULbits 32
467cc36ccd1SDavid Schultz #define kshift 5
468cc36ccd1SDavid Schultz #define kmask 31
469cc36ccd1SDavid Schultz #define ALL_ON 0xffffffff
470cc36ccd1SDavid Schultz #else
471cc36ccd1SDavid Schultz #define ULbits 16
472cc36ccd1SDavid Schultz #define kshift 4
473cc36ccd1SDavid Schultz #define kmask 15
474cc36ccd1SDavid Schultz #define ALL_ON 0xffff
475cc36ccd1SDavid Schultz #endif
476cc36ccd1SDavid Schultz 
477de9840c6SDavid Schultz #define MULTIPLE_THREADS
478d086ded3SDavid Schultz extern pthread_mutex_t __gdtoa_locks[2];
479de9840c6SDavid Schultz #define ACQUIRE_DTOA_LOCK(n)	do {				\
480de9840c6SDavid Schultz 	if (__isthreaded)					\
481d086ded3SDavid Schultz 		_pthread_mutex_lock(&__gdtoa_locks[n]);		\
482de9840c6SDavid Schultz } while(0)
483de9840c6SDavid Schultz #define FREE_DTOA_LOCK(n)	do {				\
484de9840c6SDavid Schultz 	if (__isthreaded)					\
485d086ded3SDavid Schultz 		_pthread_mutex_unlock(&__gdtoa_locks[n]);	\
486de9840c6SDavid Schultz } while(0)
487cc36ccd1SDavid Schultz 
488dcc3a331SAttilio Rao #define Kmax 9
489cc36ccd1SDavid Schultz 
490cc36ccd1SDavid Schultz  struct
491cc36ccd1SDavid Schultz Bigint {
492cc36ccd1SDavid Schultz 	struct Bigint *next;
493cc36ccd1SDavid Schultz 	int k, maxwds, sign, wds;
494cc36ccd1SDavid Schultz 	ULong x[1];
495cc36ccd1SDavid Schultz 	};
496cc36ccd1SDavid Schultz 
497cc36ccd1SDavid Schultz  typedef struct Bigint Bigint;
498cc36ccd1SDavid Schultz 
499cc36ccd1SDavid Schultz #ifdef NO_STRING_H
500cc36ccd1SDavid Schultz #ifdef DECLARE_SIZE_T
501cc36ccd1SDavid Schultz typedef unsigned int size_t;
502cc36ccd1SDavid Schultz #endif
503cc36ccd1SDavid Schultz extern void memcpy_D2A ANSI((void*, const void*, size_t));
504cc36ccd1SDavid Schultz #define Bcopy(x,y) memcpy_D2A(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int))
505cc36ccd1SDavid Schultz #else /* !NO_STRING_H */
506cc36ccd1SDavid Schultz #define Bcopy(x,y) memcpy(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int))
507cc36ccd1SDavid Schultz #endif /* NO_STRING_H */
508cc36ccd1SDavid Schultz 
509de9840c6SDavid Schultz /*
510de9840c6SDavid Schultz  * Paranoia: Protect exported symbols, including ones in files we don't
511de9840c6SDavid Schultz  * compile right now.  The standard strtof and strtod survive.
512de9840c6SDavid Schultz  */
513de9840c6SDavid Schultz #define	dtoa		__dtoa
514de9840c6SDavid Schultz #define	gdtoa		__gdtoa
515de9840c6SDavid Schultz #define	freedtoa	__freedtoa
516de9840c6SDavid Schultz #define	strtodg		__strtodg
517de9840c6SDavid Schultz #define	g_ddfmt		__g_ddfmt
518de9840c6SDavid Schultz #define	g_dfmt		__g_dfmt
519de9840c6SDavid Schultz #define	g_ffmt		__g_ffmt
520de9840c6SDavid Schultz #define	g_Qfmt		__g_Qfmt
521de9840c6SDavid Schultz #define	g_xfmt		__g_xfmt
522de9840c6SDavid Schultz #define	g_xLfmt		__g_xLfmt
523de9840c6SDavid Schultz #define	strtoId		__strtoId
524de9840c6SDavid Schultz #define	strtoIdd	__strtoIdd
525de9840c6SDavid Schultz #define	strtoIf		__strtoIf
526de9840c6SDavid Schultz #define	strtoIQ		__strtoIQ
527de9840c6SDavid Schultz #define	strtoIx		__strtoIx
528de9840c6SDavid Schultz #define	strtoIxL	__strtoIxL
529*3c87aa1dSDavid Chisnall #define	strtord_l		__strtord_l
530de9840c6SDavid Schultz #define	strtordd	__strtordd
531de9840c6SDavid Schultz #define	strtorf		__strtorf
532*3c87aa1dSDavid Chisnall #define	strtorQ_l		__strtorQ_l
533*3c87aa1dSDavid Chisnall #define	strtorx_l		__strtorx_l
534de9840c6SDavid Schultz #define	strtorxL	__strtorxL
535de9840c6SDavid Schultz #define	strtodI		__strtodI
536de9840c6SDavid Schultz #define	strtopd		__strtopd
537de9840c6SDavid Schultz #define	strtopdd	__strtopdd
538de9840c6SDavid Schultz #define	strtopf		__strtopf
539de9840c6SDavid Schultz #define	strtopQ		__strtopQ
540de9840c6SDavid Schultz #define	strtopx		__strtopx
541de9840c6SDavid Schultz #define	strtopxL	__strtopxL
542de9840c6SDavid Schultz 
543de9840c6SDavid Schultz /* Protect gdtoa-internal symbols */
544de9840c6SDavid Schultz #define	Balloc		__Balloc_D2A
545de9840c6SDavid Schultz #define	Bfree		__Bfree_D2A
546de9840c6SDavid Schultz #define	ULtoQ		__ULtoQ_D2A
547de9840c6SDavid Schultz #define	ULtof		__ULtof_D2A
548de9840c6SDavid Schultz #define	ULtod		__ULtod_D2A
549de9840c6SDavid Schultz #define	ULtodd		__ULtodd_D2A
550de9840c6SDavid Schultz #define	ULtox		__ULtox_D2A
551de9840c6SDavid Schultz #define	ULtoxL		__ULtoxL_D2A
552de9840c6SDavid Schultz #define	any_on		__any_on_D2A
553de9840c6SDavid Schultz #define	b2d		__b2d_D2A
554de9840c6SDavid Schultz #define	bigtens		__bigtens_D2A
555de9840c6SDavid Schultz #define	cmp		__cmp_D2A
556de9840c6SDavid Schultz #define	copybits	__copybits_D2A
557de9840c6SDavid Schultz #define	d2b		__d2b_D2A
558de9840c6SDavid Schultz #define	decrement	__decrement_D2A
559de9840c6SDavid Schultz #define	diff		__diff_D2A
560de9840c6SDavid Schultz #define	dtoa_result	__dtoa_result_D2A
561de9840c6SDavid Schultz #define	g__fmt		__g__fmt_D2A
562de9840c6SDavid Schultz #define	gethex		__gethex_D2A
563de9840c6SDavid Schultz #define	hexdig		__hexdig_D2A
564de9840c6SDavid Schultz #define	hexdig_init_D2A	__hexdig_init_D2A
565de9840c6SDavid Schultz #define	hexnan		__hexnan_D2A
566de9840c6SDavid Schultz #define	hi0bits		__hi0bits_D2A
56727314703SDavid Schultz #define	hi0bits_D2A	__hi0bits_D2A
568de9840c6SDavid Schultz #define	i2b		__i2b_D2A
569de9840c6SDavid Schultz #define	increment	__increment_D2A
570de9840c6SDavid Schultz #define	lo0bits		__lo0bits_D2A
571de9840c6SDavid Schultz #define	lshift		__lshift_D2A
572de9840c6SDavid Schultz #define	match		__match_D2A
573de9840c6SDavid Schultz #define	mult		__mult_D2A
574de9840c6SDavid Schultz #define	multadd		__multadd_D2A
575de9840c6SDavid Schultz #define	nrv_alloc	__nrv_alloc_D2A
576de9840c6SDavid Schultz #define	pow5mult	__pow5mult_D2A
577de9840c6SDavid Schultz #define	quorem		__quorem_D2A
578de9840c6SDavid Schultz #define	ratio		__ratio_D2A
579de9840c6SDavid Schultz #define	rshift		__rshift_D2A
580de9840c6SDavid Schultz #define	rv_alloc	__rv_alloc_D2A
581de9840c6SDavid Schultz #define	s2b		__s2b_D2A
582de9840c6SDavid Schultz #define	set_ones	__set_ones_D2A
583de9840c6SDavid Schultz #define	strcp		__strcp_D2A
584de9840c6SDavid Schultz #define	strcp_D2A      	__strcp_D2A
585de9840c6SDavid Schultz #define	strtoIg		__strtoIg_D2A
586de9840c6SDavid Schultz #define	sum		__sum_D2A
587de9840c6SDavid Schultz #define	tens		__tens_D2A
588de9840c6SDavid Schultz #define	tinytens	__tinytens_D2A
589de9840c6SDavid Schultz #define	tinytens	__tinytens_D2A
590de9840c6SDavid Schultz #define	trailz		__trailz_D2A
591de9840c6SDavid Schultz #define	ulp		__ulp_D2A
592cc36ccd1SDavid Schultz 
593cc36ccd1SDavid Schultz  extern char *dtoa_result;
594cc36ccd1SDavid Schultz  extern CONST double bigtens[], tens[], tinytens[];
595cc36ccd1SDavid Schultz  extern unsigned char hexdig[];
596cc36ccd1SDavid Schultz 
597cc36ccd1SDavid Schultz  extern Bigint *Balloc ANSI((int));
598cc36ccd1SDavid Schultz  extern void Bfree ANSI((Bigint*));
599cc36ccd1SDavid Schultz  extern void ULtof ANSI((ULong*, ULong*, Long, int));
600cc36ccd1SDavid Schultz  extern void ULtod ANSI((ULong*, ULong*, Long, int));
601cc36ccd1SDavid Schultz  extern void ULtodd ANSI((ULong*, ULong*, Long, int));
602cc36ccd1SDavid Schultz  extern void ULtoQ ANSI((ULong*, ULong*, Long, int));
603cc36ccd1SDavid Schultz  extern void ULtox ANSI((UShort*, ULong*, Long, int));
604cc36ccd1SDavid Schultz  extern void ULtoxL ANSI((ULong*, ULong*, Long, int));
605cc36ccd1SDavid Schultz  extern ULong any_on ANSI((Bigint*, int));
606cc36ccd1SDavid Schultz  extern double b2d ANSI((Bigint*, int*));
607cc36ccd1SDavid Schultz  extern int cmp ANSI((Bigint*, Bigint*));
608cc36ccd1SDavid Schultz  extern void copybits ANSI((ULong*, int, Bigint*));
609cc36ccd1SDavid Schultz  extern Bigint *d2b ANSI((double, int*, int*));
610ae2cbf4cSDavid Schultz  extern void decrement ANSI((Bigint*));
611cc36ccd1SDavid Schultz  extern Bigint *diff ANSI((Bigint*, Bigint*));
612cc36ccd1SDavid Schultz  extern char *dtoa ANSI((double d, int mode, int ndigits,
613cc36ccd1SDavid Schultz 			int *decpt, int *sign, char **rve));
61468369762SDavid Schultz  extern void freedtoa ANSI((char*));
615628f583cSDavid Schultz  extern char *gdtoa ANSI((FPI *fpi, int be, ULong *bits, int *kindp,
616628f583cSDavid Schultz 			  int mode, int ndigits, int *decpt, char **rve));
6174848dd08SDavid Schultz  extern char *g__fmt ANSI((char*, char*, char*, int, ULong, size_t));
618cc36ccd1SDavid Schultz  extern int gethex ANSI((CONST char**, FPI*, Long*, Bigint**, int));
619cc36ccd1SDavid Schultz  extern void hexdig_init_D2A(Void);
620cc36ccd1SDavid Schultz  extern int hexnan ANSI((CONST char**, FPI*, ULong*));
621cc36ccd1SDavid Schultz  extern int hi0bits ANSI((ULong));
622cc36ccd1SDavid Schultz  extern Bigint *i2b ANSI((int));
623cc36ccd1SDavid Schultz  extern Bigint *increment ANSI((Bigint*));
624cc36ccd1SDavid Schultz  extern int lo0bits ANSI((ULong*));
625cc36ccd1SDavid Schultz  extern Bigint *lshift ANSI((Bigint*, int));
626cc36ccd1SDavid Schultz  extern int match ANSI((CONST char**, char*));
627cc36ccd1SDavid Schultz  extern Bigint *mult ANSI((Bigint*, Bigint*));
628cc36ccd1SDavid Schultz  extern Bigint *multadd ANSI((Bigint*, int, int));
629cc36ccd1SDavid Schultz  extern char *nrv_alloc ANSI((char*, char **, int));
630cc36ccd1SDavid Schultz  extern Bigint *pow5mult ANSI((Bigint*, int));
631cc36ccd1SDavid Schultz  extern int quorem ANSI((Bigint*, Bigint*));
632cc36ccd1SDavid Schultz  extern double ratio ANSI((Bigint*, Bigint*));
633cc36ccd1SDavid Schultz  extern void rshift ANSI((Bigint*, int));
634cc36ccd1SDavid Schultz  extern char *rv_alloc ANSI((int));
6354848dd08SDavid Schultz  extern Bigint *s2b ANSI((CONST char*, int, int, ULong, int));
636cc36ccd1SDavid Schultz  extern Bigint *set_ones ANSI((Bigint*, int));
637cc36ccd1SDavid Schultz  extern char *strcp ANSI((char*, const char*));
638*3c87aa1dSDavid Chisnall  extern int strtodg_l ANSI((CONST char*, char**, FPI*, Long*, ULong*, locale_t));
63968369762SDavid Schultz 
64068369762SDavid Schultz  extern int strtoId ANSI((CONST char *, char **, double *, double *));
64168369762SDavid Schultz  extern int strtoIdd ANSI((CONST char *, char **, double *, double *));
64268369762SDavid Schultz  extern int strtoIf ANSI((CONST char *, char **, float *, float *));
643cc36ccd1SDavid Schultz  extern int strtoIg ANSI((CONST char*, char**, FPI*, Long*, Bigint**, int*));
64468369762SDavid Schultz  extern int strtoIQ ANSI((CONST char *, char **, void *, void *));
64568369762SDavid Schultz  extern int strtoIx ANSI((CONST char *, char **, void *, void *));
64668369762SDavid Schultz  extern int strtoIxL ANSI((CONST char *, char **, void *, void *));
647cc36ccd1SDavid Schultz  extern double strtod ANSI((const char *s00, char **se));
648*3c87aa1dSDavid Chisnall  extern double strtod_l ANSI((const char *s00, char **se, locale_t));
64968369762SDavid Schultz  extern int strtopQ ANSI((CONST char *, char **, Void *));
65068369762SDavid Schultz  extern int strtopf ANSI((CONST char *, char **, float *));
65168369762SDavid Schultz  extern int strtopd ANSI((CONST char *, char **, double *));
65268369762SDavid Schultz  extern int strtopdd ANSI((CONST char *, char **, double *));
65368369762SDavid Schultz  extern int strtopx ANSI((CONST char *, char **, Void *));
65468369762SDavid Schultz  extern int strtopxL ANSI((CONST char *, char **, Void *));
655*3c87aa1dSDavid Chisnall  extern int strtord_l ANSI((CONST char *, char **, int, double *, locale_t));
65668369762SDavid Schultz  extern int strtordd ANSI((CONST char *, char **, int, double *));
65768369762SDavid Schultz  extern int strtorf ANSI((CONST char *, char **, int, float *));
658*3c87aa1dSDavid Chisnall  extern int strtorQ_l ANSI((CONST char *, char **, int, void *, locale_t));
659*3c87aa1dSDavid Chisnall  extern int strtorx_l ANSI((CONST char *, char **, int, void *, locale_t));
66068369762SDavid Schultz  extern int strtorxL ANSI((CONST char *, char **, int, void *));
661cc36ccd1SDavid Schultz  extern Bigint *sum ANSI((Bigint*, Bigint*));
662cc36ccd1SDavid Schultz  extern int trailz ANSI((Bigint*));
66350dad48bSDavid Schultz  extern double ulp ANSI((U*));
664cc36ccd1SDavid Schultz 
665cc36ccd1SDavid Schultz #ifdef __cplusplus
666cc36ccd1SDavid Schultz }
667cc36ccd1SDavid Schultz #endif
66827314703SDavid Schultz /*
66927314703SDavid Schultz  * NAN_WORD0 and NAN_WORD1 are only referenced in strtod.c.  Prior to
67027314703SDavid Schultz  * 20050115, they used to be hard-wired here (to 0x7ff80000 and 0,
67127314703SDavid Schultz  * respectively), but now are determined by compiling and running
67227314703SDavid Schultz  * qnan.c to generate gd_qnan.h, which specifies d_QNAN0 and d_QNAN1.
67327314703SDavid Schultz  * Formerly gdtoaimp.h recommended supplying suitable -DNAN_WORD0=...
67427314703SDavid Schultz  * and -DNAN_WORD1=...  values if necessary.  This should still work.
67527314703SDavid Schultz  * (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.)
67627314703SDavid Schultz  */
677cc36ccd1SDavid Schultz #ifdef IEEE_Arith
6784848dd08SDavid Schultz #ifndef NO_INFNAN_CHECK
6794848dd08SDavid Schultz #undef INFNAN_CHECK
6804848dd08SDavid Schultz #define INFNAN_CHECK
6814848dd08SDavid Schultz #endif
682cc36ccd1SDavid Schultz #ifdef IEEE_MC68k
683cc36ccd1SDavid Schultz #define _0 0
684cc36ccd1SDavid Schultz #define _1 1
68527314703SDavid Schultz #ifndef NAN_WORD0
68627314703SDavid Schultz #define NAN_WORD0 d_QNAN0
68727314703SDavid Schultz #endif
68827314703SDavid Schultz #ifndef NAN_WORD1
68927314703SDavid Schultz #define NAN_WORD1 d_QNAN1
69027314703SDavid Schultz #endif
691cc36ccd1SDavid Schultz #else
692cc36ccd1SDavid Schultz #define _0 1
693cc36ccd1SDavid Schultz #define _1 0
69427314703SDavid Schultz #ifndef NAN_WORD0
69527314703SDavid Schultz #define NAN_WORD0 d_QNAN1
69627314703SDavid Schultz #endif
69727314703SDavid Schultz #ifndef NAN_WORD1
69827314703SDavid Schultz #define NAN_WORD1 d_QNAN0
69927314703SDavid Schultz #endif
700cc36ccd1SDavid Schultz #endif
701cc36ccd1SDavid Schultz #else
702cc36ccd1SDavid Schultz #undef INFNAN_CHECK
703cc36ccd1SDavid Schultz #endif
704cc36ccd1SDavid Schultz 
705cc36ccd1SDavid Schultz #undef SI
706cc36ccd1SDavid Schultz #ifdef Sudden_Underflow
707cc36ccd1SDavid Schultz #define SI 1
708cc36ccd1SDavid Schultz #else
709cc36ccd1SDavid Schultz #define SI 0
710cc36ccd1SDavid Schultz #endif
711cc36ccd1SDavid Schultz 
712cc36ccd1SDavid Schultz #endif /* GDTOAIMP_H_INCLUDED */
713