14bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes/****************************************************************
24bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
34bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesThe author of this software is David M. Gay.
44bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
54bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesCopyright (C) 1998-2000 by Lucent Technologies
64bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesAll Rights Reserved
74bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
84bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesPermission to use, copy, modify, and distribute this software and
94bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughesits documentation for any purpose and without fee is hereby
104bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughesgranted, provided that the above copyright notice appear in all
114bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughescopies and that both that the copyright notice and this
124bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughespermission notice and warranty disclaimer appear in supporting
134bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughesdocumentation, and that the name of Lucent or any of its entities
144bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughesnot be used in advertising or publicity pertaining to
154bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughesdistribution of the software without specific, written prior
164bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughespermission.
174bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
184bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
194bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
204bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
214bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
224bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
234bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
244bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
254bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesTHIS SOFTWARE.
264bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
274bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes****************************************************************/
284bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
294bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes/* This is a variation on dtoa.c that converts arbitary binary
304bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes   floating-point formats to and from decimal notation.  It uses
314bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes   double-precision arithmetic internally, so there are still
324bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes   various #ifdefs that adapt the calculations to the native
334bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes   double-precision arithmetic (any of IEEE, VAX D_floating,
344bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes   or IBM mainframe arithmetic).
354bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
364bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes   Please send bug reports to David M. Gay (dmg at acm dot org,
374bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes   with " at " changed at "@" and " dot " changed to ".").
384bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes */
394bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
404bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes/* On a machine with IEEE extended-precision registers, it is
414bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * necessary to specify double-precision (53-bit) rounding precision
424bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * before invoking strtod or dtoa.  If the machine uses (the equivalent
434bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * of) Intel 80x87 arithmetic, the call
444bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	_control87(PC_53, MCW_PC);
454bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * does this with many compilers.  Whether this or another call is
464bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * appropriate depends on the compiler; for this to work, it may be
474bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * necessary to #include "float.h" or another system-dependent header
484bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * file.
494bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes */
504bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
514bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes/* strtod for IEEE-, VAX-, and IBM-arithmetic machines.
524bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *
534bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * This strtod returns a nearest machine number to the input decimal
544bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * string (or sets errno to ERANGE).  With IEEE arithmetic, ties are
554bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * broken by the IEEE round-even rule.  Otherwise ties are broken by
564bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * biased rounding (add half and chop).
574bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *
584bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * Inspired loosely by William D. Clinger's paper "How to Read Floating
594bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * Point Numbers Accurately" [Proc. ACM SIGPLAN '90, pp. 112-126].
604bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *
614bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * Modifications:
624bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *
634bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	1. We only require IEEE, IBM, or VAX double-precision
644bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *		arithmetic (not IEEE double-extended).
654bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	2. We get by with floating-point arithmetic in a case that
664bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *		Clinger missed -- when we're computing d * 10^n
674bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *		for a small integer d and the integer n is not too
684bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *		much larger than 22 (the maximum integer k for which
694bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *		we can represent 10^k exactly), we may be able to
704bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *		compute (d*10^k) * 10^(e-k) with just one roundoff.
714bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	3. Rather than a bit-at-a-time adjustment of the binary
724bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *		result in the hard case, we use floating-point
734bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *		arithmetic to determine the adjustment to within
744bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *		one bit; only in really hard cases do we need to
754bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *		compute a second residual.
764bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	4. Because of 3., we don't need a large table of powers of 10
774bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *		for ten-to-e (just some small tables, e.g. of 10^k
784bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *		for 0 <= k <= 22).
794bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes */
804bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
814bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes/*
824bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define IEEE_8087 for IEEE-arithmetic machines where the least
834bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	significant byte has the lowest address.
844bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define IEEE_MC68k for IEEE-arithmetic machines where the most
854bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	significant byte has the lowest address.
864bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define Long int on machines with 32-bit ints and 64-bit longs.
874bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define Sudden_Underflow for IEEE-format machines without gradual
884bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	underflow (i.e., that flush to zero on underflow).
894bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define IBM for IBM mainframe-style floating-point arithmetic.
904bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define VAX for VAX-style floating-point arithmetic (D_floating).
914bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define No_leftright to omit left-right logic in fast floating-point
924bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	computation of dtoa and gdtoa.  This will cause modes 4 and 5 to be
934bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	treated the same as modes 2 and 3 for some inputs.
944bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3.
954bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines
964bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	that use extended-precision instructions to compute rounded
974bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	products and quotients) with IBM.
984bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define ROUND_BIASED for IEEE-format with biased rounding and arithmetic
994bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	that rounds toward +Infinity.
1004bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define ROUND_BIASED_without_Round_Up for IEEE-format with biased
1014bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	rounding when the underlying floating-point arithmetic uses
1024bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	unbiased rounding.  This prevent using ordinary floating-point
1034bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	arithmetic when the result could be computed with one rounding error.
1044bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define Inaccurate_Divide for IEEE-format with correctly rounded
1054bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	products but inaccurate quotients, e.g., for Intel i860.
1064bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define NO_LONG_LONG on machines that do not have a "long long"
1074bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	integer type (of >= 64 bits).  On such machines, you can
1084bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	#define Just_16 to store 16 bits per 32-bit Long when doing
1094bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	high-precision integer arithmetic.  Whether this speeds things
1104bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	up or slows things down depends on the machine and the number
1114bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	being converted.  If long long is available and the name is
1124bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	something other than "long long", #define Llong to be the name,
1134bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	and if "unsigned Llong" does not work as an unsigned version of
1144bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	Llong, #define #ULLong to be the corresponding unsigned type.
1154bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define KR_headers for old-style C function headers.
1164bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define Bad_float_h if your system lacks a float.h or if it does not
1174bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP,
1184bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	FLT_RADIX, FLT_ROUNDS, and DBL_MAX.
1194bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n)
1204bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	if memory is available and otherwise does something you deem
1214bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	appropriate.  If MALLOC is undefined, malloc will be invoked
1224bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	directly -- and assumed always to succeed.  Similarly, if you
1234bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	want something other than the system's free() to be called to
1244bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	recycle memory acquired from MALLOC, #define FREE to be the
1254bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	name of the alternate routine.  (FREE or free is only called in
1264bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	pathological cases, e.g., in a gdtoa call after a gdtoa return in
1274bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	mode 3 with thousands of digits requested.)
1284bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define Omit_Private_Memory to omit logic (added Jan. 1998) for making
1294bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	memory allocations from a private pool of memory when possible.
1304bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	When used, the private pool is PRIVATE_MEM bytes long:  2304 bytes,
1314bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	unless #defined to be a different length.  This default length
1324bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	suffices to get rid of MALLOC calls except for unusual cases,
1334bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	such as decimal-to-binary conversion of a very long string of
1344bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	digits.  When converting IEEE double precision values, the
1354bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	longest string gdtoa can return is about 751 bytes long.  For
1364bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	conversions by strtod of strings of 800 digits and all gdtoa
1374bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	conversions of IEEE doubles in single-threaded executions with
1384bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	8-byte pointers, PRIVATE_MEM >= 7400 appears to suffice; with
1394bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	4-byte pointers, PRIVATE_MEM >= 7112 appears adequate.
1404bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define NO_INFNAN_CHECK if you do not wish to have INFNAN_CHECK
1414bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	#defined automatically on IEEE systems.  On such systems,
1424bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	when INFNAN_CHECK is #defined, strtod checks
1434bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	for Infinity and NaN (case insensitively).
1444bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	When INFNAN_CHECK is #defined and No_Hex_NaN is not #defined,
1454bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	strtodg also accepts (case insensitively) strings of the form
1464bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	NaN(x), where x is a string of hexadecimal digits (optionally
1474bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	preceded by 0x or 0X) and spaces; if there is only one string
1484bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	of hexadecimal digits, it is taken for the fraction bits of the
1494bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	resulting NaN; if there are two or more strings of hexadecimal
1504bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	digits, each string is assigned to the next available sequence
1514bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	of 32-bit words of fractions bits (starting with the most
1524bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	significant), right-aligned in each sequence.
1534bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	Unless GDTOA_NON_PEDANTIC_NANCHECK is #defined, input "NaN(...)"
1544bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	is consumed even when ... has the wrong form (in which case the
1554bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	"(...)" is consumed but ignored).
1564bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define MULTIPLE_THREADS if the system offers preemptively scheduled
1574bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	multiple threads.  In this case, you must provide (or suitably
1584bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	#define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed
1594bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	by FREE_DTOA_LOCK(n) for n = 0 or 1.  (The second lock, accessed
1604bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	in pow5mult, ensures lazy evaluation of only one copy of high
1614bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	powers of 5; omitting this lock would introduce a small
1624bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	probability of wasting memory, but would otherwise be harmless.)
1634bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	You must also invoke freedtoa(s) to free the value s returned by
1644bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	dtoa.  You may do so whether or not MULTIPLE_THREADS is #defined.
1654bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define IMPRECISE_INEXACT if you do not care about the setting of
1664bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	the STRTOG_Inexact bits in the special case of doing IEEE double
1674bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	precision conversions (which could also be done by the strtod in
1684bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	dtoa.c).
1694bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define NO_HEX_FP to disable recognition of C9x's hexadecimal
1704bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	floating-point constants.
1714bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define -DNO_ERRNO to suppress setting errno (in strtod.c and
1724bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	strtodg.c).
1734bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define NO_STRING_H to use private versions of memcpy.
1744bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	On some K&R systems, it may also be necessary to
1754bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes *	#define DECLARE_SIZE_T in this case.
1764bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define USE_LOCALE to use the current locale's decimal_point value.
1774bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes */
1784bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
1794bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifndef GDTOAIMP_H_INCLUDED
1804bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define GDTOAIMP_H_INCLUDED
1814bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#include "gdtoa.h"
1824bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#include "gd_qnan.h"
1834bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef Honor_FLT_ROUNDS
1844bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#include <fenv.h>
1854bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
1864bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
1874bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef DEBUG
1884bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#include "stdio.h"
1894bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);}
1904bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
1914bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
1924bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#include "stdlib.h"
1934bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#include "string.h"
1944bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
1954bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef KR_headers
1964bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Char char
1974bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else
1984bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Char void
1994bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
2004bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
2014bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef MALLOC
2024bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughesextern Char *MALLOC ANSI((size_t));
2034bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else
2044bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define MALLOC malloc
2054bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
2064bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
2074bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#undef IEEE_Arith
2084bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#undef Avoid_Underflow
2094bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef IEEE_MC68k
2104bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define IEEE_Arith
2114bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
2124bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef IEEE_8087
2134bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define IEEE_Arith
2144bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
2154bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
2164bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#include "errno.h"
2174bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef Bad_float_h
2184bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
2194bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef IEEE_Arith
2204bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define DBL_DIG 15
2214bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define DBL_MAX_10_EXP 308
2224bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define DBL_MAX_EXP 1024
2234bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define FLT_RADIX 2
2244bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define DBL_MAX 1.7976931348623157e+308
2254bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
2264bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
2274bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef IBM
2284bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define DBL_DIG 16
2294bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define DBL_MAX_10_EXP 75
2304bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define DBL_MAX_EXP 63
2314bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define FLT_RADIX 16
2324bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define DBL_MAX 7.2370055773322621e+75
2334bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
2344bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
2354bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef VAX
2364bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define DBL_DIG 16
2374bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define DBL_MAX_10_EXP 38
2384bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define DBL_MAX_EXP 127
2394bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define FLT_RADIX 2
2404bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define DBL_MAX 1.7014118346046923e+38
2414bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define n_bigtens 2
2424bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
2434bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
2444bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifndef LONG_MAX
2454bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define LONG_MAX 2147483647
2464bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
2474bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
2484bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else /* ifndef Bad_float_h */
2494bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#include "float.h"
2504bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif /* Bad_float_h */
2514bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
2524bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef IEEE_Arith
2534bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Scale_Bit 0x10
2544bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define n_bigtens 5
2554bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
2564bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
2574bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef IBM
2584bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define n_bigtens 3
2594bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
2604bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
2614bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef VAX
2624bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define n_bigtens 2
2634bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
2644bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
2654bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifndef __MATH_H__
2664bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#include "math.h"
2674bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
2684bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
2694bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef __cplusplus
2704bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughesextern "C" {
2714bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
2724bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
2734bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1
2744bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesExactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined.
2754bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
2764bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
2774bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughestypedef union { double d; ULong L[2]; } U;
2784bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
2794bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef IEEE_8087
2804bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define word0(x) (x)->L[1]
2814bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define word1(x) (x)->L[0]
2824bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else
2834bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define word0(x) (x)->L[0]
2844bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define word1(x) (x)->L[1]
2854bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
2864bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define dval(x) (x)->d
2874bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
2884bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes/* The following definition of Storeinc is appropriate for MIPS processors.
2894bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * An alternative that might be better on some machines is
2904bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff)
2914bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes */
2924bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#if defined(IEEE_8087) + defined(VAX)
2934bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \
2944bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes((unsigned short *)a)[0] = (unsigned short)c, a++)
2954bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else
2964bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \
2974bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes((unsigned short *)a)[1] = (unsigned short)c, a++)
2984bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
2994bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
3004bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes/* #define P DBL_MANT_DIG */
3014bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes/* Ten_pmax = floor(P*log(2)/log(5)) */
3024bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */
3034bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */
3044bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */
3054bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
3064bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef IEEE_Arith
3074bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_shift  20
3084bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_shift1 20
3094bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_msk1    0x100000
3104bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_msk11   0x100000
3114bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_mask  0x7ff00000
3124bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define P 53
3134bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Bias 1023
3144bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Emin (-1022)
3154bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_1  0x3ff00000
3164bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_11 0x3ff00000
3174bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Ebits 11
3184bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Frac_mask  0xfffff
3194bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Frac_mask1 0xfffff
3204bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Ten_pmax 22
3214bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Bletch 0x10
3224bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Bndry_mask  0xfffff
3234bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Bndry_mask1 0xfffff
3244bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define LSB 1
3254bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Sign_bit 0x80000000
3264bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Log2P 1
3274bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Tiny0 0
3284bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Tiny1 1
3294bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Quick_max 14
3304bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Int_max 14
3314bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
3324bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifndef Flt_Rounds
3334bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef FLT_ROUNDS
3344bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Flt_Rounds FLT_ROUNDS
3354bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else
3364bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Flt_Rounds 1
3374bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
3384bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif /*Flt_Rounds*/
3394bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
3404bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else /* ifndef IEEE_Arith */
3414bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#undef  Sudden_Underflow
3424bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Sudden_Underflow
3434bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef IBM
3444bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#undef Flt_Rounds
3454bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Flt_Rounds 0
3464bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_shift  24
3474bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_shift1 24
3484bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_msk1   0x1000000
3494bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_msk11  0x1000000
3504bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_mask  0x7f000000
3514bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define P 14
3524bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Bias 65
3534bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_1  0x41000000
3544bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_11 0x41000000
3554bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Ebits 8	/* exponent has 7 bits, but 8 is the right value in b2d */
3564bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Frac_mask  0xffffff
3574bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Frac_mask1 0xffffff
3584bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Bletch 4
3594bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Ten_pmax 22
3604bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Bndry_mask  0xefffff
3614bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Bndry_mask1 0xffffff
3624bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define LSB 1
3634bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Sign_bit 0x80000000
3644bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Log2P 4
3654bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Tiny0 0x100000
3664bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Tiny1 0
3674bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Quick_max 14
3684bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Int_max 15
3694bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else /* VAX */
3704bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#undef Flt_Rounds
3714bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Flt_Rounds 1
3724bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_shift  23
3734bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_shift1 7
3744bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_msk1    0x80
3754bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_msk11   0x800000
3764bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_mask  0x7f80
3774bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define P 56
3784bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Bias 129
3794bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Emin (-127)
3804bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_1  0x40800000
3814bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Exp_11 0x4080
3824bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Ebits 8
3834bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Frac_mask  0x7fffff
3844bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Frac_mask1 0xffff007f
3854bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Ten_pmax 24
3864bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Bletch 2
3874bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Bndry_mask  0xffff007f
3884bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Bndry_mask1 0xffff007f
3894bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define LSB 0x10000
3904bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Sign_bit 0x8000
3914bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Log2P 1
3924bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Tiny0 0x80
3934bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Tiny1 0
3944bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Quick_max 15
3954bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Int_max 15
3964bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif /* IBM, VAX */
3974bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif /* IEEE_Arith */
3984bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
3994bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifndef IEEE_Arith
4004bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define ROUND_BIASED
4014bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else
4024bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef ROUND_BIASED_without_Round_Up
4034bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#undef  ROUND_BIASED
4044bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define ROUND_BIASED
4054bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
4064bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
4074bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
4084bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef RND_PRODQUOT
4094bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define rounded_product(a,b) a = rnd_prod(a, b)
4104bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define rounded_quotient(a,b) a = rnd_quot(a, b)
4114bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef KR_headers
4124bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughesextern double rnd_prod(), rnd_quot();
4134bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else
4144bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughesextern double rnd_prod(double, double), rnd_quot(double, double);
4154bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
4164bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else
4174bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define rounded_product(a,b) a *= b
4184bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define rounded_quotient(a,b) a /= b
4194bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
4204bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
4214bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))
4224bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Big1 0xffffffff
4234bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
4244bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#undef  Pack_16
4254bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifndef Pack_32
4264bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Pack_32
4274bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
4284bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
4294bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef NO_LONG_LONG
4304bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#undef ULLong
4314bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef Just_16
4324bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#undef Pack_32
4334bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Pack_16
4344bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes/* When Pack_32 is not defined, we store 16 bits per 32-bit Long.
4354bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * This makes some inner loops simpler and sometimes saves work
4364bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * during multiplications, but it often seems to make things slightly
4374bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * slower.  Hence the default is now to store 32 bits per Long.
4384bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes */
4394bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
4404bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else	/* long long available */
4414bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifndef Llong
4424bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Llong long long
4434bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
4444bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifndef ULLong
4454bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define ULLong unsigned Llong
4464bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
4474bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif /* NO_LONG_LONG */
4484bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
4494bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef Pack_32
4504bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define ULbits 32
4514bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define kshift 5
4524bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define kmask 31
4534bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define ALL_ON 0xffffffff
4544bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else
4554bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define ULbits 16
4564bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define kshift 4
4574bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define kmask 15
4584bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define ALL_ON 0xffff
4594bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
4604bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
4614bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifndef MULTIPLE_THREADS
4624bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define ACQUIRE_DTOA_LOCK(n)	/*nothing*/
4634bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define FREE_DTOA_LOCK(n)	/*nothing*/
4644bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else
4654bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#include "thread_private.h"
4664bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughesextern void *__dtoa_locks[];
4674bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define ACQUIRE_DTOA_LOCK(n)	_MUTEX_LOCK(&__dtoa_locks[n])
4684bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define FREE_DTOA_LOCK(n)	_MUTEX_UNLOCK(&__dtoa_locks[n])
4694bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
4704bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
4714bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Kmax 9
4724bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
4734bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes struct
4744bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesBigint {
4754bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	struct Bigint *next;
4764bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	int k, maxwds, sign, wds;
4774bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	ULong x[1];
4784bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	};
4794bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
4804bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes typedef struct Bigint Bigint;
4814bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
4824bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef NO_STRING_H
4834bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef DECLARE_SIZE_T
4844bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughestypedef unsigned int size_t;
4854bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
4864bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughesextern void memcpy_D2A ANSI((void*, const void*, size_t));
4874bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Bcopy(x,y) memcpy_D2A(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int))
4884bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else /* !NO_STRING_H */
4894bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Bcopy(x,y) memcpy(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int))
4904bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif /* NO_STRING_H */
4914bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
4924bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define dtoa __dtoa
4934bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define gdtoa __gdtoa
4944bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define freedtoa __freedtoa
4954bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtodg __strtodg
4964bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define g_ddfmt __g_ddfmt
4974bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define g_dfmt __g_dfmt
4984bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define g_ffmt __g_ffmt
4994bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define g_Qfmt __g_Qfmt
5004bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define g_xfmt __g_xfmt
5014bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define g_xLfmt __g_xLfmt
5024bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtoId __strtoId
5034bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtoIdd __strtoIdd
5044bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtoIf __strtoIf
5054bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtoIQ __strtoIQ
5064bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtoIx __strtoIx
5074bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtoIxL __strtoIxL
5084bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtord __strtord
5094bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtordd __strtordd
5104bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtorf __strtorf
5114bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtorQ __strtorQ
5124bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtorx __strtorx
5134bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtorxL __strtorxL
5144bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtodI __strtodI
5154bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtopd __strtopd
5164bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtopdd __strtopdd
5174bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtopf __strtopf
5184bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtopQ __strtopQ
5194bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtopx __strtopx
5204bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtopxL __strtopxL
5214bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
5224bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Balloc __Balloc_D2A
5234bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define Bfree __Bfree_D2A
5244bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define ULtoQ __ULtoQ_D2A
5254bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define ULtof __ULtof_D2A
5264bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define ULtod __ULtod_D2A
5274bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define ULtodd __ULtodd_D2A
5284bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define ULtox __ULtox_D2A
5294bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define ULtoxL __ULtoxL_D2A
5304bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define any_on __any_on_D2A
5314bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define b2d __b2d_D2A
5324bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define bigtens __bigtens_D2A
5334bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define cmp __cmp_D2A
5344bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define copybits __copybits_D2A
5354bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define d2b __d2b_D2A
5364bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define decrement __decrement_D2A
5374bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define diff __diff_D2A
5384bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define dtoa_result __dtoa_result_D2A
5394bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define g__fmt __g__fmt_D2A
5404bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define gethex __gethex_D2A
5414bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define hexdig __hexdig_D2A
5424bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define hexnan __hexnan_D2A
5434bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define hi0bits(x) __hi0bits_D2A((ULong)(x))
5444bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define hi0bits_D2A __hi0bits_D2A
5454bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define i2b __i2b_D2A
5464bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define increment __increment_D2A
5474bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define lo0bits __lo0bits_D2A
5484bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define lshift __lshift_D2A
5494bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define match __match_D2A
5504bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define mult __mult_D2A
5514bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define multadd __multadd_D2A
5524bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define nrv_alloc __nrv_alloc_D2A
5534bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define pow5mult __pow5mult_D2A
5544bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define quorem __quorem_D2A
5554bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define ratio __ratio_D2A
5564bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define rshift __rshift_D2A
5574bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define rv_alloc __rv_alloc_D2A
5584bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define s2b __s2b_D2A
5594bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define set_ones __set_ones_D2A
5604bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strcp __strcp_D2A
5614bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define strtoIg __strtoIg_D2A
5624bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define sulp __sulp_D2A
5634bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define sum __sum_D2A
5644bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define tens __tens_D2A
5654bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define tinytens __tinytens_D2A
5664bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define tinytens __tinytens_D2A
5674bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define trailz __trailz_D2A
5684bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define ulp __ulp_D2A
5694bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
5704bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern char *dtoa_result;
5714bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern CONST double bigtens[], tens[], tinytens[];
5724bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern unsigned char hexdig[];
5734bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
5744bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern Bigint *Balloc ANSI((int));
5754bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern void Bfree ANSI((Bigint*));
5764bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern void ULtof ANSI((ULong*, ULong*, Long, int));
5774bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern void ULtod ANSI((ULong*, ULong*, Long, int));
5784bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern void ULtodd ANSI((ULong*, ULong*, Long, int));
5794bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern void ULtoQ ANSI((ULong*, ULong*, Long, int));
5804bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern void ULtox ANSI((UShort*, ULong*, Long, int));
5814bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern void ULtoxL ANSI((ULong*, ULong*, Long, int));
5824bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern ULong any_on ANSI((Bigint*, int));
5834bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern double b2d ANSI((Bigint*, int*));
5844bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern int cmp ANSI((Bigint*, Bigint*));
5854bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern void copybits ANSI((ULong*, int, Bigint*));
5864bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern Bigint *d2b ANSI((double, int*, int*));
5874bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern void decrement ANSI((Bigint*));
5884bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern Bigint *diff ANSI((Bigint*, Bigint*));
5894bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern char *dtoa ANSI((double d, int mode, int ndigits,
5904bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes			int *decpt, int *sign, char **rve));
5914bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern char *g__fmt ANSI((char*, char*, char*, int, ULong, size_t));
5924bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern int gethex ANSI((CONST char**, FPI*, Long*, Bigint**, int));
5934bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern void hexdig_init_D2A(Void);
5944bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern int hexnan ANSI((CONST char**, FPI*, ULong*));
5954bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern int hi0bits_D2A ANSI((ULong));
5964bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern Bigint *i2b ANSI((int));
5974bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern Bigint *increment ANSI((Bigint*));
5984bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern int lo0bits ANSI((ULong*));
5994bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern Bigint *lshift ANSI((Bigint*, int));
6004bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern int match ANSI((CONST char**, char*));
6014bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern Bigint *mult ANSI((Bigint*, Bigint*));
6024bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern Bigint *multadd ANSI((Bigint*, int, int));
6034bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern char *nrv_alloc ANSI((char*, char **, int));
6044bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern Bigint *pow5mult ANSI((Bigint*, int));
6054bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern int quorem ANSI((Bigint*, Bigint*));
6064bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern double ratio ANSI((Bigint*, Bigint*));
6074bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern void rshift ANSI((Bigint*, int));
6084bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern char *rv_alloc ANSI((int));
6094bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern Bigint *s2b ANSI((CONST char*, int, int, ULong, int));
6104bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern Bigint *set_ones ANSI((Bigint*, int));
6114bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern char *strcp ANSI((char*, const char*));
6124bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern int strtoIg ANSI((CONST char*, char**, FPI*, Long*, Bigint**, int*));
6134bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern double strtod ANSI((const char *s00, char **se));
6144bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern Bigint *sum ANSI((Bigint*, Bigint*));
6154bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern int trailz ANSI((Bigint*));
6164bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes extern double ulp ANSI((U*));
6174bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
6184bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef __cplusplus
6194bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes}
6204bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
6214bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes/*
6224bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * NAN_WORD0 and NAN_WORD1 are only referenced in strtod.c.  Prior to
6234bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * 20050115, they used to be hard-wired here (to 0x7ff80000 and 0,
6244bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * respectively), but now are determined by compiling and running
6254bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * qnan.c to generate gd_qnan.h, which specifies d_QNAN0 and d_QNAN1.
6264bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * Formerly gdtoaimp.h recommended supplying suitable -DNAN_WORD0=...
6274bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * and -DNAN_WORD1=...  values if necessary.  This should still work.
6284bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.)
6294bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes */
6304bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef IEEE_Arith
6314bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifndef NO_INFNAN_CHECK
6324bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#undef INFNAN_CHECK
6334bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define INFNAN_CHECK
6344bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
6354bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef IEEE_MC68k
6364bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define _0 0
6374bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define _1 1
6384bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifndef NAN_WORD0
6394bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define NAN_WORD0 d_QNAN0
6404bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
6414bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifndef NAN_WORD1
6424bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define NAN_WORD1 d_QNAN1
6434bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
6444bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else
6454bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define _0 1
6464bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define _1 0
6474bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifndef NAN_WORD0
6484bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define NAN_WORD0 d_QNAN1
6494bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
6504bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifndef NAN_WORD1
6514bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define NAN_WORD1 d_QNAN0
6524bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
6534bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
6544bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else
6554bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#undef INFNAN_CHECK
6564bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
6574bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
6584bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#undef SI
6594bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef Sudden_Underflow
6604bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define SI 1
6614bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else
6624bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define SI 0
6634bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
6644bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
6654bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif /* GDTOAIMP_H_INCLUDED */
666