gdtoaimp.h 20 KB

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