Sun Jun 30 13:48:26 EDT 1991: dtoa.c: adjust dtoa to allow negative ndigits for modes 3,5,7,9 (fixed-point mode); fix rounding bug in these modes when the input d (to be converted) satisfies 10^-(ndigits+1) <= |d| < 10^-ndigits , i.e., when the result, before rounding, would be empty but might round to one digit. Adjust the decpt returned in these modes when the result is empty (i.e., when |d| <= 5 * 10^-ndigits). Tue Jul 2 21:44:00 EDT 1991 Correct an inefficiency introduced 2 days ago in dtoa's handling of integers in modes 0, 1. Mon Sep 9 23:29:38 EDT 1991 dtoa.c: remove superfluous declaration of size_t. Sun Oct 6 15:34:15 EDT 1991 dtoa.c: fix another bug in modes 3,5,7,9 when the result, before rounding, would be empty, but rounds to one digit: *decpt was low by one. Sat Jan 18 12:30:04 EST 1992 dtoa.c: add some #ifdef KR_headers lines relevant only if IBM is defined; for input decimal strings representing numbers too large, have strtod return HUGE_VAL only if __STDC__ is defined; otherwise have it return +-Infinity for IEEE arithmetic, +- the largest machine number for IBM and VAX arithmetic. (If __STDC__ is not defined, HUGE_VAL may not be defined either, or it may be wrong.) Mon Apr 27 23:13:43 EDT 1992 dtoa.c: tweak strtod (one-line addition) so the end-pointer = start pointer when the input has, e.g., only white space. Thu May 7 18:04:46 EDT 1992 dtoa.c: adjust treatment of exponent field (in strtod) to behave reasonably with huge numbers and 16-bit ints. Fri Jun 19 08:29:02 EDT 1992 dtoa.c: fix a botch in placement of #ifdef __cplusplus (which only matters if you're using a C++ compiler). Wed Oct 21 11:23:07 EDT 1992 dtoa.c: add #ifdef Bad_float_h lines for systems with missing or inferior float.h . Thu Apr 22 07:54:48 EDT 1993 dtoa.c: change < to <= in line 2059: < for(result_k = 0; sizeof(Bigint) - sizeof(unsigned long) + j < i; --- > for(result_k = 0; sizeof(Bigint) - sizeof(unsigned long) + j <= i; With 32-bit ints, the former could give too small a block for the return value when, e.g., mode = 2 or 4 and ndigits = 24 (16 for 16-bit ints). Mon Jun 21 12:56:42 EDT 1993 dtoa.c: tweak to work with 32-bit ints and 64-bit longs when compiled with -DLong=int . Wed Jan 26 11:09:16 EST 1994 dtoa.c: fix bug in strtod's handling of numbers with very negative exponents (e.g. 1.8826e-512), which should underflow to 0; fix storage leak in strtod with underflows and overflows near the underflow and overflow thresholds. Mon Feb 28 11:37:30 EST 1994 dtoa.c: 85a86,89 > * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n) > * if memory is available and otherwise does something you deem > * appropriate. If MALLOC is undefined, malloc will be invoked > * directly -- and assumed always to succeed. 87a92,95 > #ifndef MALLOC > #define MALLOC malloc > #endif > 352c360 < rv = (Bigint *)malloc(sizeof(Bigint) + (x-1)*sizeof(Long)); --- > rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(Long)); Thu Mar 3 16:56:39 EST 1994 dtoa.c: if MALLOC is #defined, declare it. Wed Jan 4 15:45:34 EST 1995 dtoa.c: add CONST qualification to tens, bigtens, tinytens (for use on embedded systems with little spare RAM). Fri Mar 1 08:55:39 EST 1996 g_fmt.c: honor the sign of 0 and return the first argument (buf). Sat Jul 6 07:59:28 EDT 1996 dtoa.c: cosmetic changes: "ULong" rather than "unsigned Long"; update comments to reflect AT&T breakup. Mon Aug 5 23:31:24 EDT 1996 dtoa.c: add comment about invoking _control87(PC_53, MCW_PC) (or the equivalent) on 80x87 machines before calling strtod or dtoa. Tue Dec 17 15:01:56 EST 1996 dtoa.c: new #define possibilities: #define INFNAN_CHECK to have strtod check (case insensitively) for "Infinity" and "NaN" on machines with IEEE arithmetic; #define MULTIPLE_THREADS if the system offers preemptively scheduled multiple threads, in which case you must supply routines ACQUIRE_DTOA_LOCK(n) and FREE_DTOA_LOCK(n) (n = 0 or 1). New void freedtoa(char*) for freeing values returned by dtoa; use of freedtoa() is required if MULTIPLE_THREADS is #defined, and is merely recommended otherwise. g_fmt.c: adjusted to invoke freedtoa(). Wed Feb 12 00:40:01 EST 1997 dtoa.c: strtod: on IEEE systems, scale to avoid intermediate underflows when the result does not underflow; compiling with -DNO_IEEE_Scale restores the old logic. Fix a bug, revealed by input string 2.2250738585072012e-308, in treating input just less than the smallest normalized number. (The bug introduced an extra ULP of error in this special case.) Tue May 12 11:13:04 EDT 1998 dtoa.c: strtod: fix a glitch introduced with the scaling of 19970212 that caused one-bit rounding errors in certain denormal numbers, such as 8.44291197326099e-309, which was read as 8.442911973260987e-309. Remove #ifdef Unsigned_Shifts logic in favor of unsigned arithmetic. Unless compiled with -DNO_LONG_LONG, use 64-bit arithmetic where possible. Fri May 15 07:49:07 EDT 1998 dtoa.c: strtod: fix another glitch with scaling to avoid underflow with IEEE arithmetic, again revealed by the input string 2.2250738585072012e-308, which was rounded to the largest denormal rather than the smallest normal double precision number. Wed Aug 5 23:27:26 EDT 1998 gdtoa.tar.gz: tweaks in response to comments from Shawn C. Sheridan (with no effect on the resulting .o files except when strtod.c is compiled with -DNO_ERRNO); bigtens --> bigtens_D2A (a symbol meant to be private to gdtoa.a). Sat Sep 12 17:05:15 EDT 1998 gdtoa.tar.gz: more changes in response to comments from Shawn C. Sheridan (including repair of a glitch in g_ffmt.c). For consistency and possible convenience, there are some new functions and some name changes to existing ones: Old New --- g_xLfmt strtoQ strtopQ --- strtopd strtodd strtopdd --- strtopf strtox strtopx --- strtopxL --- strtorxL --- strtoIxL Functions strtopd and strtopf are variations of strtod and strtof, respectively, which write their results to their final (pointer) arguments. Functions strtorf and strtord are now analogous to the other strtor* functions in that they now have a final pointer argument to which they write their results, and they return the int value they get from strtodg. The xL family (g_xLfmt, strto[Irp]xL) is a variation of the old x family (for 80-bit IEEE double-extended precision) that assumes the storage layout of the Motorola 68881's double-extended format: 80 interesting bits stored in 3 unsigned 32-bit ints (with a "hole", 16 zero bits, in the word that holds the sign and exponent). The x family now deals with 80-bit (5 unsigned 16-bit ints) rather than 96-bit arrays (3 unsigned 32-bit ints) that hold its 80-bit double-extended values. (This relaxes the alignment requirements of the x family and results in strto[Ipr]x writing 80 rather than 96 bits to their final arguments.) Each g_*fmt routine now returns a pointer to the null character that terminates the strings it writes, rather than a pointer to the beginning of that string (the first argument). These routines still return 0 (NULL) if the first argument is too short. The second argument to g_dfmt is now pointer (to a double) rather than a double value. Thu Oct 29 21:54:00 EST 1998 dtoa.c: Fix bug in strtod under -DSudden_Underflow and (the default) -DAvoid_Underflow: some numbers that should have suffered sudden underflow were scaled inappropriately (giving nonzero return values). Example: "1e-320" gave -3.6304123742133376e+280 rather than 0. Mon Nov 2 15:41:16 EST 1998 dtoa.c: tweak to remove LL suffixes from numeric constants (for compilers that offer a 64-bit long long type but do not recognize the LL constants prescribed by C9x, the proposed update to the ANSI/ISO C standard). Thanks to Earl Chew for pointing out the existence of such compilers. gdtoa.tar.gz: renamed gdtoa.tgz and updated to incorporate the above changes (of 29 Oct. and 2 Nov. 1998) to dtoa.c. Thu Mar 25 17:56:44 EST 1999 dtoa.c, gdtoa.tgz: fix a bug in strtod's reading of 4.9e-324: it returned 0 rather than the smallest denormal. Mon Apr 12 10:39:25 EDT 1999 gdtoa.tgz: test/ftest.c: change %.7g to %.8g throughout. Fri Aug 20 19:17:52 EDT 1999 gdtoa.tgz: gdtoa.c: fix two bugs reported by David Chase (thanks!): 1. An adjustment for denormalized numbers around 503 was off by one. 2. A check for "The special case" around line 551 omitted the condition that we not be at the bottom of the exponent range. Mon Sep 13 10:53:34 EDT 1999 dtoa.c: computationally invisible tweak for the benefit of people who actually read the code: 2671c2671 < && word0(d) & Exp_mask --- > && word0(d) & (Exp_mask & Exp_mask << 1) I.e., in dtoa(), the "special case" does not arise for the smallest normalized IEEE double. Thanks to Waldemar Horwat for pointing this out and suggesting the modified test above. Also, some tweaks for compilation with -DKR_headers. gdtoa.tgz: gdtoa.c: analogous change: 552c552 < if (bbits == 1 && be0 > fpi->emin) { --- > if (bbits == 1 && be0 > fpi->emin + 1) { This has no effect on the g*fmt.c routines, but might affect the computation of the shortest decimal string that rounds to the smallest normalized floating-point number of other precisions. gdota.tgz: test/d.out test/dI.out test/dd.out: updated to reflect previous changes (of 19990820); test/*.c: most test programs modified to permit #hex input. See the comments. Fri Sep 17 01:39:25 EDT 1999 Try again to update dtoa.c: somehow dtoa.c got put back to a version from 3 years ago after this "changes" file was updated on 13 Sept. 1999. One more tweak to omit a warning on some systems: 2671c2671 < && word0(d) & (Exp_mask & Exp_mask << 1) --- > && word0(d) & (Exp_mask & ~Exp_msk1) Plus changes to avoid trouble with aggressively optimizing compilers (e.g., gcc 2.95.1 under -O2). On some systems, these changes do not affect the resulting machine code; on others, the old way of viewing a double as a pair of ULongs is available with -DYES_ALIAS. Tue Sep 21 09:21:25 EDT 1999 gdtoa.tgz: changes analogous to those of 17 Sept. 1999 to dtoa.c to avoid trouble with aggressively optimizing compilers. Wed Dec 15 13:14:38 EST 1999 dtoa.c: tweak to bypass a bug with HUGE_VAL on HP systems. Mon Jan 17 18:32:52 EST 2000 dtoa.c and gdtoa.tgz: strtod: set errno = ERANGE on all inputs that underflow to zero (not just those sufficiently less than the smallest positive denormalized number). gdtoa.tgz: README: point out that compiling with -DNO_ERRNO inhibits errno assignments (by strtod and the core converter, strtodg). Tue Jan 18 16:35:31 EST 2000 dtoa.c and gdtoa.tgz: strtod: modify the test inserted yesterday so it may work correctly with buggy 80x87 compilers. (The change matters, e.g., to Microsoft Visual C++ 4.2 and 6.0.) Thu Nov 2 21:00:45 EST 2000 dtoa.c and gdtoa.tgz: 1. Fix bug in test for exact half-way cases of denormalized numbers (without -DNO_IEEE_Scale). 2. Compilation with -DNO_ERRNO prevents strtod from assigning errno = ERANGE when the result overflows or underflows to 0. 3. With IEEE arithmetic and no -DNO_IEEE_Scale, adjust scaling so ulp(d) never returns a denormalized number. This and other tweaks permit strtod and dtoa to work correctly on machines that flush underflows to zero but otherwise use IEEE arithmetic without Sudden_Underflow being #defined (and with strtod simply returning 0 instead of denormalized numbers). 4. Compilations with -DUSE_LOCALE causes strtod to use the current locale's decimal_point value. 5. Under compilations with -DINFNAN_CHECK, strtod and strtodg (case insensitively) treat "inf" the same as "infinity" and, unless compiled with -DNo_Hex_NaN, accept "nan(x)", where x is a string of hexadecimal digits and spaces, as a NaN whose value is constructed from x (as explained in comments near the top of dtoa.c and in gdtoaimp.h). 6. The default PRIVATE_MEM is increased slightly (to 2304), and comments near the top of dtoa.c provide more discussion of PRIVATE_MEM. 7. Meanings of dtoa modes 4,5,8,9 changed. See comments in dtoa.c and gdtoa.c; modes 4 and 5 may now provide shorter strings that round (in round-nearest mode) to the given double value. (Paxson's testbase program is unhappy with this new rounding, as it can introduce an error of more than one base-10 ulp when 17 or more decimal digits are requested.) 8. With IEEE arithmetic, compilation with -DHonor_FLT_ROUNDS causes strtod and dtoa to round according to FLT_ROUNDS: 0 ==> towards 0, 1 ==> nearest, 2 ==> towards +Infinity, 3 ==> towards -Infinity. 9. With IEEE arithmetic, compilation with -DSET_INEXACT causes extra computation (and sometimes slower conversions in dtoa and strtod, particularly for dtoa in cases where otherwise some simple floating- point computations would suffice) to set the IEEE inexact flag correctly. As comments in dtoa.c explain in more detail, this requires compilation in an environment (such as #include "dtoa.c" in suitable source) that provides int get_inexact(void); void clear_inexact(void); 10. On input "-x", return 0 rather than -0. gdtoa.tgz: gethex.c: adjust logic for reading hex constants to accord with current wording of the C99 standard. Previously, I thought hex constants read by strtod and friends had to have either a decimal point or an exponent field; p. 307 of the C99 standard states that both are optional. Because of the complexity of this reading, it is available only in the variant of strtod that appears in gdtoa.tgz. strtodg (gdtoa.tgz): New return value STRTOG_NaNbits (with STRTOG_NoNumber renumbered). Allow STRTOG_Neg bit in strtodg returns for STRTOG_NaN and STRTOG_NaNbits. gdtoa.tgz: Fix uninitialized variable bug in g_Qfmt.c's handling of NaNs. Mon Nov 13 14:00:05 EST 2000 gdtoa.tgz: strtodg: fix a storage leak and an apparently rare infinite loop with a boundary case of directed rounding. Example input to gdtoa/test/Qtest where the loop bug bit: r 3 35184372088831.999999999999999999999999999999999999 This was revealed by testbase for quad precision Solaris arithmetic; it did not show up in several other testbase configurations. Wed Feb 7 12:56:11 EST 2001 dtoa.c: fix bug (possible infinite loop, e.g., with 2.47032822920623272e-324) introduced 20001113 in handling the special case of a power of 2 to be rounded down one ulp. Add test (required by changes of 20001113) for the extra special case of 2^-1075 (half the smallest denormal). gdtoa.tgz: corresponding adjustments to strtod.c and strtodg.c. Tue Mar 13 00:46:09 EST 2001 gdtoa.tgz: gdtoa/strtodg.c: fix bug in handling values exactly half an ulp less than the smallest normal floating-point number; gdtoa/*test.c: fix glitch in handling "n ..." lines (intended to change "ndig"). Wed Mar 6 10:13:52 EST 2002 gdtoa.tgz: add gdtoa/test/strtodt.c and gdtoa/test/testnos3 to test strtod on hard cases posted by Fred Tydeman to comp.arch.arithmetic on 26 Feb. 1996. Add comment to gdtoa/README about strtod requiring true IEEE arithmetic (with 53-bit rounding precision on 80x87 chips). In gdtoa/test, automate selection of expected output files [xQ]*.out. Wed Mar 5 10:35:41 EST 2003 gdtoa.tgz: fix a bug in strtod's handling of 0-valued 0x... "decimal" strings. A fault was possible. Thanks to David Shultz for reporting this bug. Tue Mar 18 09:38:28 EST 2003 gdtoa.tgz: fix a glitch in strtodg.c with -DUSE_LOCALE; add #ifdef USE_LOCALE lines to g__fmt.c (to affect binary --> decimal conversions via the g*fmt routines), and add comments about -DUSE_LOCALE to README. In short, compiling strtod.c, strtodg.c, and g__fmt.c with -DUSE_LOCALE causes them to determine the decimal-point character from the current locale. (Otherwise it is '.'.) Fri Mar 21 16:36:27 EST 2003 gdtoa.tgz: gethex.c: add #ifdef USE_LOCAL logic; strtod.c: fix a glitch in handling 0x... input (the return from gethex was ignored). Wed Mar 26 15:35:10 EST 2003 gdtoa.tgz: gethex.c: pedantic (and normally invisible) change: use unsigned char for decimalpoint variable (under -DUSE_LOCALE). Sat Jan 17 23:58:52 MST 2004 gdtoa.tgz: gethex.c: supply missing parens in test for whether a denormal result should be zero, correct logic for rounding up when the result is denormal, and when returning zero or Infinity, set *bp = 0; strtod.c: switch on gethex(...) & STRTOG_Retmask rather than just on gethex(), and only copybits(..., bb) when bb is nonzero. This mattered for underflows and overflows in 0x notation. Thu Mar 25 22:34:56 MST 2004 dtoa.c and gdtoa.c/misc.c: change "(!x & 1)" to "(!x)" to avoid confusion by human readers -- the object code is unaffected (with reasonable compilers). Mon Apr 12 00:44:22 MDT 2004 dtoa.c and gdtoa.tar.gz: update contact info. for dmg and correct page numbers in comment on Steele & White (1990). gdtoa.tgz: add strtodnrp.c for a variant of strtod that is slower but does not require 53-bit rounding precision on Intel IA32 systems. Tue Apr 13 00:28:14 MDT 2004 gdtoa.tgz: strtod.c: fix glitch when both INFNAN_CHECK and No_Hex_NaN are #defined. Thanks to David Mendenhall for pointing this bug out. Wed Jan 5 22:39:17 MST 2005 gdtoa.tgz: gethex.c: fix the bug reported by Stefan Farfeleder of ignoring a binary-exponent-part if the converted number is zero. strto[pr]x.c: fix bug reported by Stefan Farfeleder in setting the exponent of denormals (which should be 0, not 1). g_xfmt.c: fix a corresponding bug with denormals. strtodg.c: fix a bug under IBM (base 16) arithemtic reported by Greg Alexander: a correction to the binary exponent for changes to the exponent of a native double value for avoiding overflow had to be multiplied by 4 ("e2 <<= 2;"). Various files: minor tweaks for portability. Sat Jan 15 15:36:03 MST 2005 gdtoa.tgz: gethex.c: fix a glitch introduced last week (and reported by Stefan Farfelder) with 0x forms with no nonzero digits before the "." character, e.g., 0x.1 (which was rendered as 0 rather than .0625). gdtoa.tgz: many files: add automatic computation of gd_qnan.h for giving the system-dependent format of a quiet NaN (the one generated for Infinity - Infinity). Tweak test/makefile so differences in the spelling of Infinity ("INF" or "Inf" on some systems) do not matter. Fix bug in strtod.c and strtodg.c under which, e.g., -.nan was read as NaN rather than unacceptable input (causing return 0). Adjust comments in README about nan(...). Fix glitch in test/dt.c. Sun Jan 16 18:22:13 MST 2005 gdtoa.tgz: strtodg.c: fix long-standing bug in handling input that rounds up to 2^nbits, e.g., strtof("16777215.5"). Thanks to Edward Moy for reporting this problem. gdtoa.tgz: Fix some bugs with -DJust_16. Thu Sep 22 22:40:16 MDT 2005 gdtoa.tgz: strtod.c: unless prevented by -DNO_FENV_H, include C99's fenv.h and with hex input, get the current rounding mode from fegetround(). With decimal input, strtod honors the rounding mode automatically. Thanks to David Schultz (das at FreeBSD dot ORG) for pointing strtodg.c: fix a bug with handling numbers very near the largest possible one, which were sometimes incorrectly converted to Infinity. Thanks to Edward Moy (emoy at apple dot com) for pointing this out. g_Qfmt.c: change strcpy to strcp. Thanks to J. T. Conklin (jtc at acorntoolworks dot com) for pointing this out. test/xtest.c: fix some subscript bugs. test/x.ou0, test/x.ou1, test/xL.: update in response to the above fix to test/xtest.c. test/makefile: add -lm to some link lines (needed for fegetround). Sun Jan 21 20:26:44 MST 2007 gdtoa.tgz: strtodg.c: fix a botch in the test of whether to increase rvbits before terminating the big for(;;) loop with dsign true: change if (hi0bits(rvb->x[(rvb->wds - 1) >> kshift]) != j) rvbits++; to if (hi0bits(rvb->x[rvb->wds - 1]) != j) rvbits++; Example of input where this bug bit: 1.9e27. Thanks to Edward Moy for providing this example. Also, simplify the preceding computation of j. test/README: add comment that strtodt needs to operate with 53-bit rounding precision on Intel x86 systems, and add a pointer to Paxson's paper. Sat Mar 15 11:44:31 MDT 2008 dtoa.c and gdtoa.tgz: with -DINFNAN_CHECK and without -DGDOTA_NON_PEDANTIC_NANCHECK, conform to the ill-advised prescription in the C99 standard of consuming (...) in "nan(...)" even when ... is not of the expected form. Allow an optional 0x or 0X to precede the string of hex digits in the expected form of ... . gdtoa.tgz: gethex.c: have, e.g., strtod("0xyz",&se) set se to "xyz". Previously it was incorrectly set to "0xyz". Thu Aug 28 22:37:35 MDT 2008 dtoa.c and gdtoa.tgz: Fix a bug in strtod when compiled with -DHonor_FLT_ROUNDS: in rounding modes other than "to nearest", strtod looped on input larger than and within a factor of 2 of the largest finite floating-point number. Since FLT_ROUNDS is buggy on some (Linux) systems in that it does not reflect calls on fesetround(), when Honor_FLT_ROUNDS is #defined, get the curren rounding mode from fegetround() rather than FLT_ROUNDS, unless Trust_FLT_ROUNDS is also #defined. gdtoa/test/getround.c in gdtoa.tgz: simply report the current rounding mode when the input line is "r" by itself. (Previously it did so, but also complained of invalid input.) gdtoa/gethex.c: fix an off-by-one bug in a rounding test; detect and deal with huge exponents (positive or negative). This affected the reading of hexadecimal floating-point values (0x...). Also set errno to ERANGE on out-of-range values (unless compiled with -DNO_ERRNO). gdtoa/strtod.c: adjust scaling of tinytens[4] (as in dtoa.c) to avoid double rounding when dealing with numbers near the bottom of the exponent range. Sat Aug 30 23:37:07 MDT 2008 gdtoa/gethex.c: ensure *bp is set to something (NULL if nothing else). Bring gdtoa/xsum0.out and gdtoa/test/xsum0.out up to date. Tue Sep 9 22:08:30 MDT 2008 gdtoa/strto*.c and gdtoa/*fmt.c: if compiled with -DUSE_LOCALE, use the current locale's decimal point character string. gdtoa/gdtoa.c: trim trailing zeros in a missed case (e.g., ndigits = 6 on 1020302). dtoa.c and gdtoa/strtod.c: on systems with IEEE arithmetic (and without NO_ERRNO being defined) set ERANGE for denormal values as well as real underflows. gdtoa/strtodg.c: fix an off-by-one bug in rounding to the largest representable magnitude when nbits is a multiple of 32. gdtoa/*fmt.c and gdtoa/gdtoa.h: bufsize changed from unsigned to size_t. gdtoaimp.h, *fmt.c: change in calling sequence to internal g__fmt(), which now explicitly checks bufsize. Relevant routines (see README) honor the current rounding mode if compiled with -DHonor_FLT_ROUNDS on IEEE-arithmetic systems that provide the C99 fegetround() function. gdtoa/test/getround.c can optionally be compiled with -DHonor_FLT_ROUNDS and/or -DUSE_MY_LOCALE for manual testing of gdtoa.a compiled with -DHonor_FLT_ROUNDS or -DUSE_LOCALE. Fri Oct 10 20:07:15 MDT 2008 gdtoa/gethex.c: fix a bug reading hexadecimal floating-point values starting with "0xd" for a nonzero digit d (such as "0x1.0002p3"). The bug caused the values to be read as zero with endptr set incorrectly. Tue Oct 28 00:14:08 MDT 2008 gdtoa/strtod.c: fix a comment glitch (with commented {}). Tue Nov 11 23:05:25 MST 2008 gdtoa: fix a glitch in the strto* routines when compiled with -DUSE_LOCALE and the locale's decimal-point string is two or more characters long. Wrong conversions were then possible. Fri Dec 5 18:20:36 MST 2008 gdtoa.tgz: fix bugs with reading C99-style hexadecimal floating-point values when compiled with -DPack_16; on IEEE-arithmetic systems, make INFNAN_CHECK the default unless NO_INFNAN_CHECK is #defined. (This is consistent with dtoa.c, which has worked this way for a while.) dtoa.c: add recognition of C99-style hexadecimal floating-point values (unless compiled with NO_HEX_FP is #defined). Thu Dec 11 23:10:23 MST 2008 dtoa.c: omit an unused variable. Fri Jan 2 22:45:33 MST 2009 dtoa.c: tweak to banish some compiler warnings. Sun Mar 1 20:57:22 MST 2009 dtoa.c, gdtoa/{g__fmt.c, gethex.c, strtod.c, strtodg.c}: change malloc to MALLOC. dtoa.c and gdtoa/gdtoaimp.h and gdtoa/misc.c: reduce Kmax, and use MALLOC and FREE or free for huge blocks, which are possible only in pathological cases, such as dtoa calls in mode 3 with thousands of digits requested, or strtod() calls with thousand of digits. For the latter case, I have an alternate approach that runs much faster and uses less memory, but finding time to get it ready for distribution may take a while. Mon Mar 16 00:32:43 MDT 2009 dtoa.c: Fix a bug under -DUSE_LOCALE in handling "decimal point" strings more than one character long. dtoa.c and gdtoa/misc.c: Remove a buggy test activated with -DDEBUG. dtoa.c and gdtoa/gdtoa.c: simplify logic for "4 leading 0 bits". dtoa.c: Add logic (that can be disabled with -DNO_STRTOD_BIGCOMP and that) to strtod for more efficiently handling a very long input string. It proceeds by initially truncating the input string, then if necessary comparing the whole string with a decimal expansion to decide close cases. This logic is only used for input more than STRTOD_DIGLIM digits long (default 40), and for now only applies to IEEE arithmetic (for want of other kinds of platforms on which to run tests). This only appears worthwhile for absurdly long input strings, so a corresponding update to gdtoa does not seem warranted. dtoa.c, gdtoa.tgz: tweaks (mostly adding unnecessary parens) to silence "gcc -Wall" warnings. Aside from a couple of minor changes to banish erroneous warnings about uninitialized variables, the tweaks do not affect the generated object code. Sat Apr 11 23:25:58 MDT 2009 dtoa.c: fix glitch in compiling with -DNo_Hex_NaN and the bug of accepting (e.g.) ".nan" or ".inf" as NaN or Infinity. gdtoa.tgz: tweaks to silence warnings from "gcc -Wstrict-aliasing=2"; update xsum0.out files. Sun Apr 19 23:40:24 MDT 2009 dtoa.c, gdtoa/misc.c: do not attempt to allocate large memory blocks from the private memory pool (which was an unlikely event, but a bug). gdtoa/strtopx.c, gdtoa/strtopxL.c, gdtoa/strtorx.c, gdtoa/strtorxL.c: supply explicit bit for Infinity. Note that the Q routines (which do not supply this bit) are appropriate for Sparc quad precision (probably known as long double with most current compilers). Wed Dec 9 08:14:52 MST 2009 gdtoa.tgz: add gdtoa/printf.c* and modify makefile so "make Printf" adds a printf to gdtoa.a (to be accessed with #include "stdio1.h" to get gdtoa/stdio1.h, which you might install in some standard place). On Intel/AMD i386, x86_64, and Sparc systems, this adds formats %La, %Le, %Lf and %Lg to handle long double. On x86_64 systems, it also adds %Lqa, %Lqe, %Lqf and %Lqg to handle 128-bit bit types (called __float128 by gcc and _Quad by the Intel compiler). In gdtoa/test, "make pf_test" tests this printf (provided the system is an i386, x86_64, or Sparc system). On x86_64 systems, "make pf_testLq" tests the %Lq... formats (briefly). Mon Jan 11 22:25:17 MST 2010 dtoa.c: fix a minor performance bug and, under compilation with -DDEBUG, an erroneous error message "oversize b in quorem" in strtod's processing of some input that underflows to zero. Also fix a bug in bigcomp()'s handling of numbers that will scale to denormal values. The increments that bigcomp applied were ignoring the effects of denormalization. Sat Jan 23 00:25:54 MST 2010 dtoa.c: Fix some glitches in recently introduced changes meant to speed up returns in pedantic cases. In quorem, adjust #ifdef DEBUG stuff so it does not complain when bigcomp() calls quorem on input near the smallest representable number and rounding up by a bit causes a quorem return > 9 (which in this case is not a bug). Fix a memory leak in the unlikely case of overflow only being detected after some high-precision integer computations. Fix an off-by-one bug in handling a large number of digits with a few nonzero digits, followed by many zeros, and then some nonzero digits. (This does not happen with sensible input.) Fix an off-by-one bug in a recently introduced quick test for underflow (i.e., zero result) on input at the bottom of the exponent range. Thanks to Mark Dickinson for pointing these bugs out. dtoa.c and gdtoa/strtod.c: Fix an obscure bug in strtod's handling of some inputs of many digits at the bottom of the exponent range: results were sometimes off by a bit when gdtoa/strtod.c or dtoa.c was compiled without -DNO_IEEE_SCALE and, for dtoa.c, when compiled with -DNO_STRTOD_BIGCOMP. gdtoa/test/testnos3: add some examples that went wrong before the present changes. Sat Jan 23 23:29:02 MST 2010 dtoa.c: more tweaks relevant only to absurd input. Tue Feb 2 23:05:34 MST 2010 dtoa.c: add test for setting errno = ERANGE when input of many digits is rounded to Infinity or underflows to zero. Fix a memory leak in such instances. gdtoa/strtod.c: make some corresponding changes. Wed Jul 7 09:25:46 MDT 2010 dtoa.c: adjust to use bigcomp when necessary when compiled with -DHonor_FLT_ROUNDS (and without -DNO_STRTOD_BIGCOMP), and the rounding mode is torwards +Infinity. An input (supplied by Rick Regan ) where this matters is 1.100000000000000088817841970012523233890533447265626 gdtoa/strtod.c: fix errors (introduced 20090411) when compiled with -DHonor_FLT_ROUNDS. Wed Sep 15 09:00:26 MDT 2010 dtoa.c, gdtoa/dtoa.c, gdtoa/gdtoa.c: fix bugs with -DROUND_BIASED pointed out by Jay Foad. Mon Sep 27 13:43:30 MDT 2010 gdtoa/gdtoa.c: fix a glitch (not revealed by compilation) in the changes of 15 Sept. 2010. Fri Nov 5 13:02:41 MDT 2010 dtoa.c: fix a bug related to bigcomp: decimal strings with all zeros before the decimal point more than 40 significant digits that required use of bigcomp might be converted very incorrectly. Example: .010000000000000000057612911342378542997169 . Thanks to Rick Regan for reporting the symptoms and providing an example. 20110304: dtoa.c, gdtoa/gdtoaimp.h, gdtoa/strtod.c: if ROUND_BIASED_without_Round_Up is #defined, assume ROUND_BIASED and omit the quick computation that would use ordinary arithmetic to compute the correctly rounded result with one rounding error. If you want biased rounding with IEEE-style format "double" and will operate with rounding toward +Infinity, it suffices to #define ROUND_BIASED (and thus retain the quick computation when it is appropriate). gdtoa/gdtoa.h: change default Long from long to int (with the goal of portability when compiling without -DLong=... specified). On some 64-bit systems, long is a 64-bit type; we need a 32-bit type here. dtoa.c, gdtoa/gdtoa.c: fix a glith with ndigits with mode = 4 at the bottom of the exponent range, e.g., 1e-323. 20110321: dtoa.c, gdtoaimp.h: add comment that defining No_leftright will sometimes cause dtoa (or gdtoa) modes 4 and 5 to be treated the same as modes 2 and 3, respectively (and thus not work as intended). 20110428: dtoa.c: fix a glitch under compilation with Honor_FLT_ROUNDS and NO_HEX_FP #defined. 20111102: gdota.tgz: add field int_max to struct FPI and adjust gdtoa.c and *fmt.c so gdtoa.c tests against fpi->int_max rather than Int_max. This only affects some conversions by g_ffmt.c, which in some cases produced too many digits, such as the case added to the end of tests/testnos. 20120417 dtoa.c: augment a test in bigcomp() to correctly compare a long input string of digits with a computed string after all of the input string has otherwise been processed. This matters only rarely; a string for which it matters (reported by Herman Geza) is 1.8254370818746402660437411213933955878019332885742187 . 20120423 dtoa.c: add a comment that gcc's -ffast-math flag disables IEEE arithmetic (whence dtoa and strtod may not function right if you use this flag or related flags). 20121220 dtoa.c and gdtoa.tgz: to avoid a possible one-time race when Infinity or NaN appear in decimal->binary conversions done in parallel threads, replace hexdig_init() with static initialization. 20121223 gdtoa.tgz: add variants g_ddfmt_p(), g_dfmt_p(), g_ffmt_p(), g_Qfmt_p(), g_xfmt_p(), and g_xLfmt_p() of g_ddfmt(), g_dfmt(), g_ffmt(), g_Qfmt(), g_xfmt(), and g_xLfmt(), respectively, that have an additional final int argument that governs details of the rendering of Infinity and NaN. For more details, see the updated README. 20130129 dtoa.c: fix an obscure memory leak in gethex(). (See the new ret_tinyf label.) Thanks to avernar@gmail.com for pointing this issue out. 20131122 dtoa.c: fix a possible glitch with strtod in deciding whether a decimal value less in absolute value than the smallest denormal should be rounded to zero. (The fix is to force use of bigcomp() when at the bottom of the exponent range and we otherwise would have returned 0.) Thanks to Rick Regan for sending an example that illustrated the bug. 20131209 dtoa.c, gdtoa.tgz: when strtod computes its starting approximation, allow z to involve one more digit for IEEE arithmetic and two more digits for IBM-mainframe and VAX arithmetics. Thanks to Walter Qian (water.qian@gmail.com) for suggesting this change, which makes some conversions faster. 20150112 dtoa.c: "ifdef KR_headers" stuff removed; modifications to "#ifdef MULTIPLE_THREADS": function void set_max_dtoa_threads(unsigned int n); is provided and unsigned int dtoa_get_threadno(void); is expected to be available to return the current thread number. After set_max_dtoa_threads(n), calls on strtod and dtoa by threads with thread numbers < n avoid calls on ACQUIRE_DTOA_LOCK and FREE_DTOA_LOCK by keeping thread-specific copies of entities for which changes by other threads would otherwise cause trouble. See the updated comments in dtoa.c about MULTIPLE_THREADS. 20150119 dtoa.c: fix a glitch (possible fault) in the updates of 20150112. 20151020 dtoa.c: add a test for dtoa() to return "1" under mode 4 when converting some very small powers of 10, such as 1e-322 with ndigits = 4 and 1e-319 with ndigits = 7 (examples provided by jay.foad@gmail.com). 20160219 dtoa.c: fix glitches when compiled with both MULTIPLE_THREADS and Honor_FLT_ROUNDS #defined (a senseless combination). gdtoa.tgz: make changes similar to the "#ifdef MULTIPLE_THREADS" changes to dtoa.c of 20150112. Adjust gdtoa(...,mode,...) to assume "round near" when mode is 0 or 1. Make various tweaks to banish (useless) warnings from "gcc -Wall -Wextra". Thanks to Jarkko Hietaniemi for advocating the latter exercise (and correcting a typo in README). 20160220 gdtoa.tgz: in gdtoa/test, adjust dItest.c, ddtest.c, dtest,c, ftest.c to banish pedantic warnings that appear with "gcc -O2 -Wall -Wextra" but not with "gcc -O -Wall -Wextra". 20160307 dtoa.c: fix glitches with floating-point values in hexadecimal notation: some values that should overflow to (appropriately signed) Infinity, such as 0x1p1025, were mishandled, and values greater than 0x1p-1075 and less than 0x1.0000000000001p-1075 where treated as zero rather than the smallest denormal number. gdtoa.tgz: fix a bug with hexadecimal input greater than the smallest denormal and less than the smallest denormal times the smallest number greater than one. In round-to-nearest values, such values should round to the smallest denormal rather than to zero. Thanks to Albert Chan for bug reports. 20160325 dtoa.c: fix a bug whereby dtoa(...,mode,...) with, e.g., mode = 2 or 3 could return a string with trailing zeros, contrary to specification. An example provided by Albert Chan: dtoa(81320560005., 2, 10,...). gdtoa.tgz: fix the analogous bug in gdtoa/dtoa.c and gdtoa/gdtoa.c and apply the bug fix of 20151020 to gdtoa/dtoa.c. 20160429 dtoa.c: new variant dtoa_r() of dtoa(), with new trailing arguments char *s0 and size_t s0len. When s0len is large enough to accommodate the desired return value (including a trailing NULL byte) and possibly some intermediate trailing zeros, dtoa_r() returns s0. Otherwise dtoa_r() returns NULL, and if the call had the form dtoa_r(..., rve, s0, s0len) with rve not NULL, then a subsequent call with s0len greater than *rve - (char*)0 should succeed in returning s0. On systems with 64-bit integer arithmetic and IEEE arithmetic, new logic in dtoa.c sometimes makes strtod(), dtoa(), and dtoa_r() faster than before -- an order of magnitude or more faster in some cases. The new logic can be suppressed by compilation with -DNO_BF96 or -DNO_LONG_LONG. Thanks to Albert Chan for prompting me to revisit use of 64-bit integer arithmetic here. dtoa.c, gdtoa.tgz (file dtoa.c): Fix a bug with dtoa mode 0 when Honor_FLT_ROUNDS is defined: with some inputs and nondefault rounding modes (e.g., 1.23 with round toward zero), the returned string was off by one. When the new 64-bit integer logic is used, the test in question is very unlikely to be used. This is another bug reported by Albert Chan. 20160502 dtoa.c: add "ll" suffix to long long decimal constants (array pfive). 20160503 dtoa.c: fix some glitches in obscure cases; remove "#ifdef DELAY_URES" logic, which gave wrong results in rare cases. 20160504 dtoa.c: fix more rarely seen bugs with dtoa()'s rounding of final digits. 20160505 dtoa.c: fix some glitches in strtod() when Honor_FLT_ROUNDS is defined: zero was returned for some decimal values that should have been rounded to +- the smallest denormal, and +-Infinity was returned for some hexadecimal strings with huge values that should have been rounded to +- the largest finite value. 20160506 gdtoa.tgz: analogous bug fixes to those of 20160505. dtoa.c: fix glitches with some denormals and some directed roundings. 20160507 dtoa.c: fix strtod overflow tests. 20160508 dtoa.c: strtod: fix rounding bugs with some denormals and with some strings of more than 19 digits; dtoa: fix rarely seen off-by-one bug in the final digit with modes 2 and 3. 20160510 dtoa.c: strtod: fix a glitch that caused some values less than the half smallest denormal not to round to zero, and adjust a test that in rare cases incorrectly avoided a longer computation; dtoa: fix a glitch with -DNO_BF96 -DHonor_FLT_ROUNDS. 20160513 dtoa.c: tighten a test that occasionally falsely indicated sufficiency of an approximate computation. In some difficult but unlikely cases, the value returned by strtod was off by one bit. Fix some tests used with directed roundings that sometimes caused (and dota_r) modes 2 and 3 to return off-by-one values. Thanks to Albert Chan for providing examples. 20160514 dtoa.c: strtod: tighten a variant, missed yesterday, of a test that occasionally falsely indicated sufficiency of an approximate computation. Also apply to denormals a test hitherto only applied to normal numbers for sufficiency of an approximate computation. 20160516 dtoa.c (versions >= 20160429, without -DNO_BF96): fix more glitches with directed roundings. 20160518 dtoa.c: strtod (without -DNO_BF96): minor efficiency improvement on some inputs with more than 19 significant digits. 20160521 dtoa.c (without -DNO_BF96): strtod: fix glitches with directed rounding of denormals; dtoa and strtod: fix some bugs with -DSET_INEXACT. 20160523 dtoa.c (without -DNO_BF96): strtod: fix a bug in rounding some denormal values; dtoa: fix a potential glitch with -DSET_INEXACT. Thanks to Albert Chan for providing examples of the strtod bug. 20160607 dtoa.c (without -DNO_BF96): strtod: fix a rarely seen 1-bit error converting strings of more than 19 digits. Thanks to Albert Chan for examples. 20160611 dtoa.c (without -DNO_BF96): minor performance improvement on some strtod inputs, using truncated rather than rounded 96-bit approximate powers of 10. Thanks to Albert Chan for suggesting use of truncated rather than rounded constants. 20161024 dtoa.c: tweak for C++ compilation with MALLOC or REALLOC #defined. 20161107 dtoa.c: make errno assignments via a macro, Set_errno(x), that by default is "errno = x", but can be set to something else in a local errno.h, such as "#define Set_errno(x) _set_errno(x)", which works with some compilers on Microsoft systems, but not others, and is not known to be necessary with any of those compilers. Note that a local errno.h (included in dtoa.c via #include "errno.h") probably should #include . 20180411 dtoa.c: fix glitches (compile errors) with compilation under -DSudden_Underflow . 20180730 strtodg.c in gdtoa.c: fix a glitch, introduced 20160506, with some return values of +-Infinity: the STRTOG_Overflow bit was not set. strtoIg.c in gdtoa.c: undo some changes, probably of 20160506, that caused trouble with subnormal values, such as 1.23e-320, on which strtoId (which calls strtoIg) returned two equal values, rather than values differing by one in the least-significant bit. test/dt.c: when compiled with -DUSE_fpinit, initially invoke fpinit_ASL() (found in the AMPL/solver interface library) to set Intel 80x87-style floating point arithmetic to 53-bit rounding precision. test/dtest.c: change output to say "strtord consumes" rather than "strtod consumes". test/d.out: update to reflect the above change to dtest.c. 20230515 qnan.c in gdtoa.tgz: fix a bug that bit on little-endian machines: in the two printf statements involving subscripts _0 and _1, the subscripts should be 0 and 1. 20230822 dtoa.c: banish two pedantic warnings when compiled with NO_LONG_LONG #defined. (No change to the resulting object code.) 20231101 dtoa.c: change #ifdef Check_FLT_ROUNDS try_quick = Rounding == 1; #endif to #ifdef Check_FLT_ROUNDS try_quick = Rounding == 1; #else try_quick = 1; #endif so try_quick is initialized when both USE_BF96 and SET_INEXACT are undefined. Thanks to Peter Hoddie for pointing out the need for such a change. 20231209 Tweak to prevent spurious diagnostics, e.g., by UndefinedBehaviorSanitizer: change s1 = s; while((c = *++s) >= '0' && c <= '9') L = 10*L + c - '0'; if (s - s1 > 8 || L > 19999) to while((c = *++s) >= '0' && c <= '9') { if (L <= 19999) L = 10*L + c - '0'; } if (L > 19999) in dtoa.c, and in strtod.c and strtodg.c in gdtoa.tgz. Thanks to Peter Hoddie for suggesting this change. 20240130 dtoa.c and gdtoa.tgz: Fix bug in strtod's handling of 0x1.fffffffffffffp-1023 which gave 0 rather than the expected 0x1p-1022. Thanks to Rick Regan (exploringbinary@gmail.com) for this example. 20240202 dtoa.c and gdtoa.tgz: another try: fix bug in strtod's handling of 0x1.fffffffffffffp-1023 which gave 0 rather than the expected 0x1p-1022. The previous fix worked on that input, but broke some other (denormal) inputs. Thanks again to Rick Regan (exploringbinary@gmail.com) for providing examples. 20240206 dtoa.c and gdtoa.tgz: yet another try: fix bugs in strtod's handling of hex input that should give 0x1p-1022. The previous fixes sometimes worked, but broke some other (denormal) inputs. Thanks again to Rick Regan (exploringbinary@gmail.com) for providing examples. 20240207 dtoa.c and gdtoa.tgz: yesterday's fix to bugs in strtod's handling of hex input that should give 0x1p-1022 broke rounding in other cases of denormal input (due to a missing pair of parentheses). Thanks again to Rick Regan (exploringbinary@gmail.com) for providing more examples. 20240213 dtoa.c and gdtoa.tgz: fixes to some other cases of hexadecimal input; adjust recent change for compilation with -DHonor_FLT_ROUNDS -DTrust_FLT_ROUNDS. Thannks to Rick Regan (exploringbinary@gmail.com) for providing more examples. 20240215 dtoa.c and gdtoa.tgz: fix a glitch that only matters when multiple threads are in use. 20240221 dtoa.c and gdtoa.tgz: fix another glitch with nondefault rounding modes and hexadecimal inputs near the smallest representable normal number. 20240224 dtoa.c and gdtoa.tgz: fix yet another glitch with nondefault rounding modes and hexadecimal inputs near the smallest representable normal number. Thanks again to Rick Regan (exploringbinary@gmail.com) for providing another example. 20240715 dtoa.c: Fix a bug that caused dtoa to render 6.9999999999999996e-161 as 7e-161. The fix was removal of a couple of lines, changing if (!(zb & ures) && (ures-rb) << (1 - eulp) < ulp) { if ((ures + rb) << (1 - eulp) < ulp) goto Roundup; goto Fast_failed1; } to if (!(zb & ures) && (ures-rb) << (1 - eulp) < ulp) goto Fast_failed1; Fix a bug that caused dtoa to render .000491831912544516 as .0004918319125445159 . The fix was to add another test, changing if (ures < res || (ures == res && dig & 1)) goto Roundup; to if (ures < res || (ures == res && dig & 1) || (dig == 9 && 2*ures <= ulp)) goto Roundup; 20240718 dtoa.c: Tweak the change of 20240715 to fix a bug that caused dtoa to render 6.9999999999999996e-161 as 7e-161 to allow more efficiency in some cases: change if (!(zb & ures) && (ures-rb) << (1 - eulp) < ulp) goto Fast_failed1; to if (!(zb & ures) && (ures-rb) << (1 - eulp) < ulp) { if ((ures + rb) << (2 - eulp) < ulp) goto Roundup; goto Fast_failed1; }