version 1.6, 2007/02/03 16:44:02 |
version 1.9, 2011/03/20 23:15:35 |
|
|
* #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines |
* #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines |
* that use extended-precision instructions to compute rounded |
* that use extended-precision instructions to compute rounded |
* products and quotients) with IBM. |
* products and quotients) with IBM. |
* #define ROUND_BIASED for IEEE-format with biased rounding. |
* #define ROUND_BIASED for IEEE-format with biased rounding and arithmetic |
|
* that rounds toward +Infinity. |
|
* #define ROUND_BIASED_without_Round_Up for IEEE-format with biased |
|
* rounding when the underlying floating-point arithmetic uses |
|
* unbiased rounding. This prevent using ordinary floating-point |
|
* arithmetic when the result could be computed with one rounding error. |
* #define Inaccurate_Divide for IEEE-format with correctly rounded |
* #define Inaccurate_Divide for IEEE-format with correctly rounded |
* products but inaccurate quotients, e.g., for Intel i860. |
* products but inaccurate quotients, e.g., for Intel i860. |
* #define NO_LONG_LONG on machines that do not have a "long long" |
* #define NO_LONG_LONG on machines that do not have a "long long" |
|
|
* #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n) |
* #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n) |
* if memory is available and otherwise does something you deem |
* if memory is available and otherwise does something you deem |
* appropriate. If MALLOC is undefined, malloc will be invoked |
* appropriate. If MALLOC is undefined, malloc will be invoked |
* directly -- and assumed always to succeed. |
* directly -- and assumed always to succeed. Similarly, if you |
|
* want something other than the system's free() to be called to |
|
* recycle memory acquired from MALLOC, #define FREE to be the |
|
* name of the alternate routine. (FREE or free is only called in |
|
* pathological cases, e.g., in a gdtoa call after a gdtoa return in |
|
* mode 3 with thousands of digits requested.) |
* #define Omit_Private_Memory to omit logic (added Jan. 1998) for making |
* #define Omit_Private_Memory to omit logic (added Jan. 1998) for making |
* memory allocations from a private pool of memory when possible. |
* memory allocations from a private pool of memory when possible. |
* When used, the private pool is PRIVATE_MEM bytes long: 2304 bytes, |
* When used, the private pool is PRIVATE_MEM bytes long: 2304 bytes, |
|
|
* conversions of IEEE doubles in single-threaded executions with |
* conversions of IEEE doubles in single-threaded executions with |
* 8-byte pointers, PRIVATE_MEM >= 7400 appears to suffice; with |
* 8-byte pointers, PRIVATE_MEM >= 7400 appears to suffice; with |
* 4-byte pointers, PRIVATE_MEM >= 7112 appears adequate. |
* 4-byte pointers, PRIVATE_MEM >= 7112 appears adequate. |
* #define INFNAN_CHECK on IEEE systems to cause strtod to check for |
* #define NO_INFNAN_CHECK if you do not wish to have INFNAN_CHECK |
* Infinity and NaN (case insensitively). |
* #defined automatically on IEEE systems. On such systems, |
|
* when INFNAN_CHECK is #defined, strtod checks |
|
* for Infinity and NaN (case insensitively). |
* When INFNAN_CHECK is #defined and No_Hex_NaN is not #defined, |
* When INFNAN_CHECK is #defined and No_Hex_NaN is not #defined, |
* strtodg also accepts (case insensitively) strings of the form |
* strtodg also accepts (case insensitively) strings of the form |
* NaN(x), where x is a string of hexadecimal digits and spaces; |
* NaN(x), where x is a string of hexadecimal digits (optionally |
* if there is only one string of hexadecimal digits, it is taken |
* preceded by 0x or 0X) and spaces; if there is only one string |
* for the fraction bits of the resulting NaN; if there are two or |
* of hexadecimal digits, it is taken for the fraction bits of the |
* more strings of hexadecimal digits, each string is assigned |
* resulting NaN; if there are two or more strings of hexadecimal |
* to the next available sequence of 32-bit words of fractions |
* digits, each string is assigned to the next available sequence |
* bits (starting with the most significant), right-aligned in |
* of 32-bit words of fractions bits (starting with the most |
* each sequence. |
* significant), right-aligned in each sequence. |
|
* Unless GDTOA_NON_PEDANTIC_NANCHECK is #defined, input "NaN(...)" |
|
* is consumed even when ... has the wrong form (in which case the |
|
* "(...)" is consumed but ignored). |
* #define MULTIPLE_THREADS if the system offers preemptively scheduled |
* #define MULTIPLE_THREADS if the system offers preemptively scheduled |
* multiple threads. In this case, you must provide (or suitably |
* multiple threads. In this case, you must provide (or suitably |
* #define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed |
* #define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed |
|
|
* dtoa. You may do so whether or not MULTIPLE_THREADS is #defined. |
* dtoa. You may do so whether or not MULTIPLE_THREADS is #defined. |
* #define IMPRECISE_INEXACT if you do not care about the setting of |
* #define IMPRECISE_INEXACT if you do not care about the setting of |
* the STRTOG_Inexact bits in the special case of doing IEEE double |
* the STRTOG_Inexact bits in the special case of doing IEEE double |
* precision conversions (which could also be done by the strtog in |
* precision conversions (which could also be done by the strtod in |
* dtoa.c). |
* dtoa.c). |
* #define NO_HEX_FP to disable recognition of C9x's hexadecimal |
* #define NO_HEX_FP to disable recognition of C9x's hexadecimal |
* floating-point constants. |
* floating-point constants. |
|
|
* #define NO_STRING_H to use private versions of memcpy. |
* #define NO_STRING_H to use private versions of memcpy. |
* On some K&R systems, it may also be necessary to |
* On some K&R systems, it may also be necessary to |
* #define DECLARE_SIZE_T in this case. |
* #define DECLARE_SIZE_T in this case. |
* #define YES_ALIAS to permit aliasing certain double values with |
|
* arrays of ULongs. This leads to slightly better code with |
|
* some compilers and was always used prior to 19990916, but it |
|
* is not strictly legal and can cause trouble with aggressively |
|
* optimizing compilers (e.g., gcc 2.95.1 under -O2). |
|
* #define USE_LOCALE to use the current locale's decimal_point value. |
* #define USE_LOCALE to use the current locale's decimal_point value. |
*/ |
*/ |
|
|
|
|
#define GDTOAIMP_H_INCLUDED |
#define GDTOAIMP_H_INCLUDED |
#include "gdtoa.h" |
#include "gdtoa.h" |
#include "gd_qnan.h" |
#include "gd_qnan.h" |
|
#ifdef Honor_FLT_ROUNDS |
|
#include <fenv.h> |
|
#endif |
|
|
#ifdef DEBUG |
#ifdef DEBUG |
#include "stdio.h" |
#include "stdio.h" |
|
|
Exactly one of IEEE_LITTLE_ENDIAN, IEEE_BIG_ENDIAN, VAX, or IBM should be defined. |
Exactly one of IEEE_LITTLE_ENDIAN, IEEE_BIG_ENDIAN, VAX, or IBM should be defined. |
#endif |
#endif |
|
|
typedef union { double d; ULong L[2]; } U; |
typedef union { double d; ULong L[2]; } __attribute__((__may_alias__)) U; |
|
|
#ifdef YES_ALIAS |
#ifdef YES_ALIAS |
#define dval(x) x |
#define dval(x) x |
#ifdef IEEE_LITTLE_ENDIAN |
#ifdef IEEE_LITTLE_ENDIAN |
#define word0(x) ((ULong *)&x)[1] |
#define word0(x) ((ULong *)x)[1] |
#define word1(x) ((ULong *)&x)[0] |
#define word1(x) ((ULong *)x)[0] |
#else |
#else |
#define word0(x) ((ULong *)&x)[0] |
#define word0(x) ((ULong *)x)[0] |
#define word1(x) ((ULong *)&x)[1] |
#define word1(x) ((ULong *)x)[1] |
#endif |
#endif |
#else /* !YES_ALIAS */ |
#else /* !YES_ALIAS */ |
#ifdef IEEE_LITTLE_ENDIAN |
#ifdef IEEE_LITTLE_ENDIAN |
#define word0(x) ( /* LINTED */ (U*)&x)->L[1] |
#define word0(x) ( /* LINTED */ (U*)x)->L[1] |
#define word1(x) ( /* LINTED */ (U*)&x)->L[0] |
#define word1(x) ( /* LINTED */ (U*)x)->L[0] |
#else |
#else |
#define word0(x) ( /* LINTED */ (U*)&x)->L[0] |
#define word0(x) ( /* LINTED */ (U*)x)->L[0] |
#define word1(x) ( /* LINTED */ (U*)&x)->L[1] |
#define word1(x) ( /* LINTED */ (U*)x)->L[1] |
#endif |
#endif |
#define dval(x) ( /* LINTED */ (U*)&x)->d |
#define dval(x) ( /* LINTED */ (U*)x)->d |
#endif /* YES_ALIAS */ |
#endif /* YES_ALIAS */ |
|
|
/* The following definition of Storeinc is appropriate for MIPS processors. |
/* The following definition of Storeinc is appropriate for MIPS processors. |
Line 414 typedef union { double d; ULong L[2]; } |
|
Line 427 typedef union { double d; ULong L[2]; } |
|
|
|
#ifndef IEEE_Arith |
#ifndef IEEE_Arith |
#define ROUND_BIASED |
#define ROUND_BIASED |
|
#else |
|
#ifdef ROUND_BIASED_without_Round_Up |
|
#undef ROUND_BIASED |
|
#define ROUND_BIASED |
|
#endif |
#endif |
#endif |
|
|
#ifdef RND_PRODQUOT |
#ifdef RND_PRODQUOT |
Line 489 extern mutex_t __gdtoa_locks[2]; |
|
Line 507 extern mutex_t __gdtoa_locks[2]; |
|
} while (/* CONSTCOND */ 0) |
} while (/* CONSTCOND */ 0) |
#endif |
#endif |
|
|
#define Kmax 15 |
#define Kmax (sizeof(size_t) << 3) |
|
|
struct |
struct |
Bigint { |
Bigint { |
Line 563 extern void memcpy_D2A ANSI((void*, cons |
|
Line 581 extern void memcpy_D2A ANSI((void*, cons |
|
extern CONST double bigtens[], tens[], tinytens[]; |
extern CONST double bigtens[], tens[], tinytens[]; |
extern unsigned char hexdig[]; |
extern unsigned char hexdig[]; |
|
|
extern Bigint *Balloc ANSI((int)); |
extern Bigint *Balloc ANSI((size_t)); |
extern void Bfree ANSI((Bigint*)); |
extern void Bfree ANSI((Bigint*)); |
extern void ULtof ANSI((ULong*, ULong*, Long, int)); |
extern void ULtof ANSI((ULong*, ULong*, Long, int)); |
extern void ULtod ANSI((ULong*, ULong*, Long, int)); |
extern void ULtod ANSI((ULong*, ULong*, Long, int)); |
Line 576 extern void memcpy_D2A ANSI((void*, cons |
|
Line 594 extern void memcpy_D2A ANSI((void*, cons |
|
extern int cmp ANSI((Bigint*, Bigint*)); |
extern int cmp ANSI((Bigint*, Bigint*)); |
extern void copybits ANSI((ULong*, int, Bigint*)); |
extern void copybits ANSI((ULong*, int, Bigint*)); |
extern Bigint *d2b ANSI((double, int*, int*)); |
extern Bigint *d2b ANSI((double, int*, int*)); |
extern int decrement ANSI((Bigint*)); |
extern void decrement ANSI((Bigint*)); |
extern Bigint *diff ANSI((Bigint*, Bigint*)); |
extern Bigint *diff ANSI((Bigint*, Bigint*)); |
extern char *dtoa ANSI((double d, int mode, int ndigits, |
extern char *dtoa ANSI((double d, int mode, int ndigits, |
int *decpt, int *sign, char **rve)); |
int *decpt, int *sign, char **rve)); |
extern char *g__fmt ANSI((char*, char*, char*, int, ULong)); |
extern char *g__fmt ANSI((char*, char*, char*, int, ULong, size_t)); |
extern int gethex ANSI((CONST char**, CONST FPI*, Long*, Bigint**, int)); |
extern int gethex ANSI((CONST char**, CONST FPI*, Long*, Bigint**, int)); |
extern void hexdig_init_D2A(Void); |
extern void hexdig_init_D2A(Void); |
extern int hexnan ANSI((CONST char**, CONST FPI*, ULong*)); |
extern int hexnan ANSI((CONST char**, CONST FPI*, ULong*)); |
Line 598 extern void memcpy_D2A ANSI((void*, cons |
|
Line 616 extern void memcpy_D2A ANSI((void*, cons |
|
extern double ratio ANSI((Bigint*, Bigint*)); |
extern double ratio ANSI((Bigint*, Bigint*)); |
extern void rshift ANSI((Bigint*, int)); |
extern void rshift ANSI((Bigint*, int)); |
extern char *rv_alloc ANSI((size_t)); |
extern char *rv_alloc ANSI((size_t)); |
extern Bigint *s2b ANSI((CONST char*, int, int, ULong)); |
extern Bigint *s2b ANSI((CONST char*, int, int, ULong, int)); |
extern Bigint *set_ones ANSI((Bigint*, int)); |
extern Bigint *set_ones ANSI((Bigint*, int)); |
extern char *strcp ANSI((char*, const char*)); |
extern char *strcp ANSI((char*, const char*)); |
extern int strtoIg ANSI((CONST char*, char**, FPI*, Long*, Bigint**, int*)); |
extern int strtoIg ANSI((CONST char*, char**, FPI*, Long*, Bigint**, int*)); |
extern double strtod ANSI((const char *s00, char **se)); |
extern double strtod ANSI((const char *s00, char **se)); |
extern Bigint *sum ANSI((Bigint*, Bigint*)); |
extern Bigint *sum ANSI((Bigint*, Bigint*)); |
extern int trailz ANSI((CONST Bigint*)); |
extern int trailz ANSI((CONST Bigint*)); |
extern double ulp ANSI((double)); |
/*###626 [lint] syntax error '*' [249]%%%*/ |
|
/*###626 [lint] incomplete or misplaced function definition [22]%%%*/ |
|
extern double ulp ANSI((U*)); |
|
|
#ifdef __cplusplus |
#ifdef __cplusplus |
} |
} |
Line 620 extern void memcpy_D2A ANSI((void*, cons |
|
Line 640 extern void memcpy_D2A ANSI((void*, cons |
|
* (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.) |
* (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.) |
*/ |
*/ |
#ifdef IEEE_Arith |
#ifdef IEEE_Arith |
|
#ifndef NO_INFNAN_CHECK |
|
#undef INFNAN_CHECK |
|
#define INFNAN_CHECK |
|
#endif |
#ifdef IEEE_BIG_ENDIAN |
#ifdef IEEE_BIG_ENDIAN |
#define _0 0 |
#define _0 0 |
#define _1 1 |
#define _1 1 |