1219422SdasSun Jun 30 13:48:26 EDT 1991: 2219422Sdas dtoa.c: adjust dtoa to allow negative ndigits for modes 3,5,7,9 3219422Sdas(fixed-point mode); fix rounding bug in these modes when the input 4219422Sdasd (to be converted) satisfies 10^-(ndigits+1) <= |d| < 10^-ndigits , 5219422Sdasi.e., when the result, before rounding, would be empty but might 6219422Sdasround to one digit. Adjust the decpt returned in these modes when 7219422Sdasthe result is empty (i.e., when |d| <= 5 * 10^-ndigits). 8219422Sdas 9219422SdasTue Jul 2 21:44:00 EDT 1991 10219422Sdas Correct an inefficiency introduced 2 days ago in dtoa's handling of 11219422Sdasintegers in modes 0, 1. 12219422Sdas 13219422SdasMon Sep 9 23:29:38 EDT 1991 14219422Sdas dtoa.c: remove superfluous declaration of size_t. 15219422Sdas 16219422SdasSun Oct 6 15:34:15 EDT 1991 17219422Sdas dtoa.c: fix another bug in modes 3,5,7,9 when the result, before 18219422Sdasrounding, would be empty, but rounds to one digit: *decpt was low by 19219422Sdasone. 20219422Sdas 21219422SdasSat Jan 18 12:30:04 EST 1992 22219422Sdas dtoa.c: add some #ifdef KR_headers lines relevant only if IBM is 23219422Sdasdefined; for input decimal strings representing numbers too large, have 24219422Sdasstrtod return HUGE_VAL only if __STDC__ is defined; otherwise have it 25219422Sdasreturn +-Infinity for IEEE arithmetic, +- the largest machine number 26219422Sdasfor IBM and VAX arithmetic. (If __STDC__ is not defined, HUGE_VAL may 27219422Sdasnot be defined either, or it may be wrong.) 28219422Sdas 29219422SdasMon Apr 27 23:13:43 EDT 1992 30219422Sdas dtoa.c: tweak strtod (one-line addition) so the end-pointer = start 31219422Sdaspointer when the input has, e.g., only white space. 32219422Sdas 33219422SdasThu May 7 18:04:46 EDT 1992 34219422Sdas dtoa.c: adjust treatment of exponent field (in strtod) to behave 35219422Sdasreasonably with huge numbers and 16-bit ints. 36219422Sdas 37219422SdasFri Jun 19 08:29:02 EDT 1992 38219422Sdas dtoa.c: fix a botch in placement of #ifdef __cplusplus (which only 39219422Sdasmatters if you're using a C++ compiler). 40219422Sdas 41219422SdasWed Oct 21 11:23:07 EDT 1992 42219422Sdas dtoa.c: add #ifdef Bad_float_h lines for systems with missing or 43219422Sdasinferior float.h . 44219422Sdas 45219422SdasThu Apr 22 07:54:48 EDT 1993 46219422Sdas dtoa.c: change < to <= in line 2059: 47219422Sdas< for(result_k = 0; sizeof(Bigint) - sizeof(unsigned long) + j < i; 48219422Sdas--- 49219422Sdas> for(result_k = 0; sizeof(Bigint) - sizeof(unsigned long) + j <= i; 50219422SdasWith 32-bit ints, the former could give too small a block for the return 51219422Sdasvalue when, e.g., mode = 2 or 4 and ndigits = 24 (16 for 16-bit ints). 52219422Sdas 53219422SdasMon Jun 21 12:56:42 EDT 1993 54219422Sdas dtoa.c: tweak to work with 32-bit ints and 64-bit longs 55219422Sdaswhen compiled with -DLong=int . 56219422Sdas 57219422SdasWed Jan 26 11:09:16 EST 1994 58219422Sdas dtoa.c: fix bug in strtod's handling of numbers with very 59219422Sdasnegative exponents (e.g. 1.8826e-512), which should underflow to 0; 60219422Sdasfix storage leak in strtod with underflows and overflows near 61219422Sdasthe underflow and overflow thresholds. 62219422Sdas 63219422SdasMon Feb 28 11:37:30 EST 1994 64219422Sdas dtoa.c: 65219422Sdas85a86,89 66219422Sdas> * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n) 67219422Sdas> * if memory is available and otherwise does something you deem 68219422Sdas> * appropriate. If MALLOC is undefined, malloc will be invoked 69219422Sdas> * directly -- and assumed always to succeed. 70219422Sdas87a92,95 71219422Sdas> #ifndef MALLOC 72219422Sdas> #define MALLOC malloc 73219422Sdas> #endif 74219422Sdas> 75219422Sdas352c360 76219422Sdas< rv = (Bigint *)malloc(sizeof(Bigint) + (x-1)*sizeof(Long)); 77219422Sdas--- 78219422Sdas> rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(Long)); 79219422Sdas 80219422SdasThu Mar 3 16:56:39 EST 1994 81219422Sdas dtoa.c: if MALLOC is #defined, declare it. 82219422Sdas 83219422SdasWed Jan 4 15:45:34 EST 1995 84219422Sdas dtoa.c: add CONST qualification to tens, bigtens, tinytens (for use 85219422Sdason embedded systems with little spare RAM). 86219422Sdas 87219422SdasFri Mar 1 08:55:39 EST 1996 88219422Sdas g_fmt.c: honor the sign of 0 and return the first argument (buf). 89219422Sdas 90219422SdasSat Jul 6 07:59:28 EDT 1996 91219422Sdas dtoa.c: cosmetic changes: "ULong" rather than "unsigned Long"; 92219422Sdasupdate comments to reflect AT&T breakup. 93219422Sdas 94219422SdasMon Aug 5 23:31:24 EDT 1996 95219422Sdas dtoa.c: add comment about invoking _control87(PC_53, MCW_PC) 96219422Sdas(or the equivalent) on 80x87 machines before calling strtod or dtoa. 97219422Sdas 98219422SdasTue Dec 17 15:01:56 EST 1996 99219422Sdas dtoa.c: new #define possibilities: #define INFNAN_CHECK to have 100219422Sdasstrtod check (case insensitively) for "Infinity" and "NaN" on machines 101219422Sdaswith IEEE arithmetic; #define MULTIPLE_THREADS if the system offers 102219422Sdaspreemptively scheduled multiple threads, in which case you must supply 103219422Sdasroutines ACQUIRE_DTOA_LOCK(n) and FREE_DTOA_LOCK(n) (n = 0 or 1). 104219422SdasNew void freedtoa(char*) for freeing values returned by dtoa; use of 105219422Sdasfreedtoa() is required if MULTIPLE_THREADS is #defined, and is merely 106219422Sdasrecommended otherwise. 107219422Sdas g_fmt.c: adjusted to invoke freedtoa(). 108219422Sdas 109219422SdasWed Feb 12 00:40:01 EST 1997 110219422Sdas dtoa.c: strtod: on IEEE systems, scale to avoid intermediate 111219422Sdasunderflows when the result does not underflow; compiling with 112219422Sdas-DNO_IEEE_Scale restores the old logic. Fix a bug, revealed by 113219422Sdasinput string 2.2250738585072012e-308, in treating input just less 114219422Sdasthan the smallest normalized number. (The bug introduced an extra 115219422SdasULP of error in this special case.) 116219422Sdas 117219422SdasTue May 12 11:13:04 EDT 1998 118219422Sdas dtoa.c: strtod: fix a glitch introduced with the scaling of 19970212 119219422Sdasthat caused one-bit rounding errors in certain denormal numbers, such 120219422Sdasas 8.44291197326099e-309, which was read as 8.442911973260987e-309. 121219422SdasRemove #ifdef Unsigned_Shifts logic in favor of unsigned arithmetic. 122219422SdasUnless compiled with -DNO_LONG_LONG, use 64-bit arithmetic where 123219422Sdaspossible. 124219422Sdas 125219422SdasFri May 15 07:49:07 EDT 1998 126219422Sdas dtoa.c: strtod: fix another glitch with scaling to avoid underflow 127219422Sdaswith IEEE arithmetic, again revealed by the input string 128219422Sdas2.2250738585072012e-308, which was rounded to the largest denormal 129219422Sdasrather than the smallest normal double precision number. 130219422Sdas 131219422SdasWed Aug 5 23:27:26 EDT 1998 132219422Sdas gdtoa.tar.gz: tweaks in response to comments from Shawn C. Sheridan 133219422Sdas(with no effect on the resulting .o files except when strtod.c is 134219422Sdascompiled with -DNO_ERRNO); bigtens --> bigtens_D2A (a symbol meant 135219422Sdasto be private to gdtoa.a). 136219422Sdas 137219422SdasSat Sep 12 17:05:15 EDT 1998 138219422Sdas gdtoa.tar.gz: more changes in response to comments from Shawn C. 139219422SdasSheridan (including repair of a glitch in g_ffmt.c). For consistency 140219422Sdasand possible convenience, there are some new functions and some name 141219422Sdaschanges to existing ones: 142219422Sdas Old New 143219422Sdas --- g_xLfmt 144219422Sdas strtoQ strtopQ 145219422Sdas --- strtopd 146219422Sdas strtodd strtopdd 147219422Sdas --- strtopf 148219422Sdas strtox strtopx 149219422Sdas --- strtopxL 150219422Sdas --- strtorxL 151219422Sdas --- strtoIxL 152219422SdasFunctions strtopd and strtopf are variations of strtod and strtof, 153219422Sdasrespectively, which write their results to their final (pointer) 154219422Sdasarguments. Functions strtorf and strtord are now analogous to the 155219422Sdasother strtor* functions in that they now have a final pointer 156219422Sdasargument to which they write their results, and they return the 157219422Sdasint value they get from strtodg. 158219422Sdas The xL family (g_xLfmt, strto[Irp]xL) is a variation of the old x 159219422Sdasfamily (for 80-bit IEEE double-extended precision) that assumes the 160219422Sdasstorage layout of the Motorola 68881's double-extended format: 80 161219422Sdasinteresting bits stored in 3 unsigned 32-bit ints (with a "hole", 16 162219422Sdaszero bits, in the word that holds the sign and exponent). The x 163219422Sdasfamily now deals with 80-bit (5 unsigned 16-bit ints) rather than 164219422Sdas96-bit arrays (3 unsigned 32-bit ints) that hold its 80-bit 165219422Sdasdouble-extended values. (This relaxes the alignment requirements of 166219422Sdasthe x family and results in strto[Ipr]x writing 80 rather than 96 bits 167219422Sdasto their final arguments.) 168219422Sdas Each g_*fmt routine now returns a pointer to the null character 169219422Sdasthat terminates the strings it writes, rather than a pointer to 170219422Sdasthe beginning of that string (the first argument). These routines 171219422Sdasstill return 0 (NULL) if the first argument is too short. 172219422Sdas The second argument to g_dfmt is now pointer (to a double) rather 173219422Sdasthan a double value. 174219422Sdas 175219422SdasThu Oct 29 21:54:00 EST 1998 176219422Sdas dtoa.c: Fix bug in strtod under -DSudden_Underflow and (the default) 177219422Sdas-DAvoid_Underflow: some numbers that should have suffered sudden 178219422Sdasunderflow were scaled inappropriately (giving nonzero return values). 179219422SdasExample: "1e-320" gave -3.6304123742133376e+280 rather than 0. 180219422Sdas 181219422SdasMon Nov 2 15:41:16 EST 1998 182219422Sdas dtoa.c: tweak to remove LL suffixes from numeric constants (for 183219422Sdascompilers that offer a 64-bit long long type but do not recognize the 184219422SdasLL constants prescribed by C9x, the proposed update to the ANSI/ISO C 185219422Sdasstandard). Thanks to Earl Chew for pointing out the existence of such 186219422Sdascompilers. 187219422Sdas gdtoa.tar.gz: renamed gdtoa.tgz and updated to incorporate the above 188219422Sdaschanges (of 29 Oct. and 2 Nov. 1998) to dtoa.c. 189219422Sdas 190219422SdasThu Mar 25 17:56:44 EST 1999 191219422Sdas dtoa.c, gdtoa.tgz: fix a bug in strtod's reading of 4.9e-324: 192219422Sdasit returned 0 rather than the smallest denormal. 193219422Sdas 194219422SdasMon Apr 12 10:39:25 EDT 1999 195219422Sdas gdtoa.tgz: test/ftest.c: change %.7g to %.8g throughout. 196219422Sdas 197219422SdasFri Aug 20 19:17:52 EDT 1999 198219422Sdas gdtoa.tgz: gdtoa.c: fix two bugs reported by David Chase (thanks!): 199219422Sdas1. An adjustment for denormalized numbers around 503 was off by one. 200219422Sdas2. A check for "The special case" around line 551 omitted the condition 201219422Sdasthat we not be at the bottom of the exponent range. 202219422Sdas 203219422SdasMon Sep 13 10:53:34 EDT 1999 204219422Sdas dtoa.c: computationally invisible tweak for the benefit of people 205219422Sdaswho actually read the code: 206219422Sdas 207219422Sdas2671c2671 208219422Sdas< && word0(d) & Exp_mask 209219422Sdas--- 210219422Sdas> && word0(d) & (Exp_mask & Exp_mask << 1) 211219422Sdas 212219422SdasI.e., in dtoa(), the "special case" does not arise for the smallest 213219422Sdasnormalized IEEE double. Thanks to Waldemar Horwat for pointing this 214219422Sdasout and suggesting the modified test above. Also, some tweaks for 215219422Sdascompilation with -DKR_headers. 216219422Sdas gdtoa.tgz: gdtoa.c: analogous change: 217219422Sdas 218219422Sdas552c552 219219422Sdas< if (bbits == 1 && be0 > fpi->emin) { 220219422Sdas--- 221219422Sdas> if (bbits == 1 && be0 > fpi->emin + 1) { 222219422Sdas 223219422SdasThis has no effect on the g*fmt.c routines, but might affect the 224219422Sdascomputation of the shortest decimal string that rounds to the 225219422Sdassmallest normalized floating-point number of other precisions. 226219422Sdas gdota.tgz: test/d.out test/dI.out test/dd.out: updated to reflect 227219422Sdasprevious changes (of 19990820); test/*.c: most test programs modified 228219422Sdasto permit #hex input. See the comments. 229219422Sdas 230219422SdasFri Sep 17 01:39:25 EDT 1999 231219422Sdas Try again to update dtoa.c: somehow dtoa.c got put back to a version 232219422Sdasfrom 3 years ago after this "changes" file was updated on 13 Sept. 1999. 233219422SdasOne more tweak to omit a warning on some systems: 234219422Sdas2671c2671 235219422Sdas< && word0(d) & (Exp_mask & Exp_mask << 1) 236219422Sdas--- 237219422Sdas> && word0(d) & (Exp_mask & ~Exp_msk1) 238219422SdasPlus changes to avoid trouble with aggressively optimizing compilers 239219422Sdas(e.g., gcc 2.95.1 under -O2). On some systems, these changes do not 240219422Sdasaffect the resulting machine code; on others, the old way of viewing 241219422Sdasa double as a pair of ULongs is available with -DYES_ALIAS. 242219422Sdas 243219422SdasTue Sep 21 09:21:25 EDT 1999 244219422Sdas gdtoa.tgz: changes analogous to those of 17 Sept. 1999 to dtoa.c to 245219422Sdasavoid trouble with aggressively optimizing compilers. 246219422Sdas 247219422SdasWed Dec 15 13:14:38 EST 1999 248219422Sdas dtoa.c: tweak to bypass a bug with HUGE_VAL on HP systems. 249219422Sdas 250219422SdasMon Jan 17 18:32:52 EST 2000 251219422Sdas dtoa.c and gdtoa.tgz: strtod: set errno = ERANGE on all inputs that 252219422Sdasunderflow to zero (not just those sufficiently less than the smallest 253219422Sdaspositive denormalized number). 254219422Sdas gdtoa.tgz: README: point out that compiling with -DNO_ERRNO inhibits 255219422Sdaserrno assignments (by strtod and the core converter, strtodg). 256219422Sdas 257219422SdasTue Jan 18 16:35:31 EST 2000 258219422Sdas dtoa.c and gdtoa.tgz: strtod: modify the test inserted yesterday so 259219422Sdasit may work correctly with buggy 80x87 compilers. (The change matters, 260219422Sdase.g., to Microsoft Visual C++ 4.2 and 6.0.) 261219422Sdas 262219422SdasThu Nov 2 21:00:45 EST 2000 263219422Sdas dtoa.c and gdtoa.tgz: 264219422Sdas1. Fix bug in test for exact half-way cases of denormalized numbers 265219422Sdas (without -DNO_IEEE_Scale). 266219422Sdas2. Compilation with -DNO_ERRNO prevents strtod from assigning 267219422Sdas errno = ERANGE when the result overflows or underflows to 0. 268219422Sdas3. With IEEE arithmetic and no -DNO_IEEE_Scale, adjust scaling so 269219422Sdas ulp(d) never returns a denormalized number. This and other tweaks 270219422Sdas permit strtod and dtoa to work correctly on machines that flush 271219422Sdas underflows to zero but otherwise use IEEE arithmetic without 272219422Sdas Sudden_Underflow being #defined (and with strtod simply returning 0 273219422Sdas instead of denormalized numbers). 274219422Sdas4. Compilations with -DUSE_LOCALE causes strtod to use the current 275219422Sdas locale's decimal_point value. 276219422Sdas5. Under compilations with -DINFNAN_CHECK, strtod and strtodg (case 277219422Sdas insensitively) treat "inf" the same as "infinity" and, unless 278219422Sdas compiled with -DNo_Hex_NaN, accept "nan(x)", where x is a string of 279219422Sdas hexadecimal digits and spaces, as a NaN whose value is constructed 280219422Sdas from x (as explained in comments near the top of dtoa.c and in 281219422Sdas gdtoaimp.h). 282219422Sdas6. The default PRIVATE_MEM is increased slightly (to 2304), and comments 283219422Sdas near the top of dtoa.c provide more discussion of PRIVATE_MEM. 284219422Sdas7. Meanings of dtoa modes 4,5,8,9 changed. See comments in dtoa.c and 285219422Sdas gdtoa.c; modes 4 and 5 may now provide shorter strings that round 286219422Sdas (in round-nearest mode) to the given double value. (Paxson's 287219422Sdas testbase program is unhappy with this new rounding, as it can 288219422Sdas introduce an error of more than one base-10 ulp when 17 or more 289219422Sdas decimal digits are requested.) 290219422Sdas8. With IEEE arithmetic, compilation with -DHonor_FLT_ROUNDS causes 291219422Sdas strtod and dtoa to round according to FLT_ROUNDS: 292219422Sdas 0 ==> towards 0, 293219422Sdas 1 ==> nearest, 294219422Sdas 2 ==> towards +Infinity, 295219422Sdas 3 ==> towards -Infinity. 296219422Sdas9. With IEEE arithmetic, compilation with -DSET_INEXACT causes extra 297219422Sdas computation (and sometimes slower conversions in dtoa and strtod, 298219422Sdas particularly for dtoa in cases where otherwise some simple floating- 299219422Sdas point computations would suffice) to set the IEEE inexact flag 300219422Sdas correctly. As comments in dtoa.c explain in more detail, this 301219422Sdas requires compilation in an environment (such as #include "dtoa.c" 302219422Sdas in suitable source) that provides 303219422Sdas int get_inexact(void); 304219422Sdas void clear_inexact(void); 305219422Sdas10. On input "-x", return 0 rather than -0. 306219422Sdas 307219422Sdasgdtoa.tgz: gethex.c: adjust logic for reading hex constants to accord 308219422Sdaswith current wording of the C99 standard. Previously, I thought hex 309219422Sdasconstants read by strtod and friends had to have either a decimal point 310219422Sdasor an exponent field; p. 307 of the C99 standard states that both are 311219422Sdasoptional. Because of the complexity of this reading, it is available 312219422Sdasonly in the variant of strtod that appears in gdtoa.tgz. 313219422Sdas 314219422Sdasstrtodg (gdtoa.tgz): New return value STRTOG_NaNbits (with 315219422SdasSTRTOG_NoNumber renumbered). Allow STRTOG_Neg bit in strtodg returns 316219422Sdasfor STRTOG_NaN and STRTOG_NaNbits. 317219422Sdas 318219422Sdasgdtoa.tgz: Fix uninitialized variable bug in g_Qfmt.c's handling of NaNs. 319219422Sdas 320219422SdasMon Nov 13 14:00:05 EST 2000 321219422Sdas gdtoa.tgz: strtodg: fix a storage leak and an apparently rare infinite 322219422Sdasloop with a boundary case of directed rounding. Example input to 323219422Sdasgdtoa/test/Qtest where the loop bug bit: 324219422Sdas r 3 325219422Sdas 35184372088831.999999999999999999999999999999999999 326219422SdasThis was revealed by testbase for quad precision Solaris arithmetic; 327219422Sdasit did not show up in several other testbase configurations. 328219422Sdas 329219422SdasWed Feb 7 12:56:11 EST 2001 330219422Sdas dtoa.c: fix bug (possible infinite loop, e.g., with 331219422Sdas2.47032822920623272e-324) introduced 20001113 in handling the special 332219422Sdascase of a power of 2 to be rounded down one ulp. Add test (required 333219422Sdasby changes of 20001113) for the extra special case of 2^-1075 (half 334219422Sdasthe smallest denormal). 335219422Sdas gdtoa.tgz: corresponding adjustments to strtod.c and strtodg.c. 336219422Sdas 337219422SdasTue Mar 13 00:46:09 EST 2001 338219422Sdas gdtoa.tgz: gdtoa/strtodg.c: fix bug in handling values exactly half 339219422Sdasan ulp less than the smallest normal floating-point number; 340219422Sdasgdtoa/*test.c: fix glitch in handling "n ..." lines (intended to 341219422Sdaschange "ndig"). 342219422Sdas 343219422SdasWed Mar 6 10:13:52 EST 2002 344219422Sdas gdtoa.tgz: add gdtoa/test/strtodt.c and gdtoa/test/testnos3 to test 345219422Sdasstrtod on hard cases posted by Fred Tydeman to comp.arch.arithmetic on 346219422Sdas26 Feb. 1996. Add comment to gdtoa/README about strtod requiring true 347219422SdasIEEE arithmetic (with 53-bit rounding precision on 80x87 chips). 348219422SdasIn gdtoa/test, automate selection of expected output files [xQ]*.out. 349219422Sdas 350219422SdasWed Mar 5 10:35:41 EST 2003 351219422Sdas gdtoa.tgz: fix a bug in strtod's handling of 0-valued 0x... "decimal" 352219422Sdasstrings. A fault was possible. Thanks to David Shultz for reporting 353219422Sdasthis bug. 354219422Sdas 355219422SdasTue Mar 18 09:38:28 EST 2003 356219422Sdas gdtoa.tgz: fix a glitch in strtodg.c with -DUSE_LOCALE; add #ifdef 357219422SdasUSE_LOCALE lines to g__fmt.c (to affect binary --> decimal conversions 358219422Sdasvia the g*fmt routines), and add comments about -DUSE_LOCALE to README. 359219422SdasIn short, compiling strtod.c, strtodg.c, and g__fmt.c with -DUSE_LOCALE 360219422Sdascauses them to determine the decimal-point character from the current 361219422Sdaslocale. (Otherwise it is '.'.) 362219422Sdas 363219422SdasFri Mar 21 16:36:27 EST 2003 364219422Sdas gdtoa.tgz: gethex.c: add #ifdef USE_LOCAL logic; strtod.c: fix a 365219422Sdasglitch in handling 0x... input (the return from gethex was ignored). 366219422Sdas 367219422SdasWed Mar 26 15:35:10 EST 2003 368219422Sdas gdtoa.tgz: gethex.c: pedantic (and normally invisible) change: 369219422Sdasuse unsigned char for decimalpoint variable (under -DUSE_LOCALE). 370219422Sdas 371219422SdasSat Jan 17 23:58:52 MST 2004 372219422Sdas gdtoa.tgz: gethex.c: supply missing parens in test for whether a 373219422Sdasdenormal result should be zero, correct logic for rounding up when the 374219422Sdasresult is denormal, and when returning zero or Infinity, set *bp = 0; 375219422Sdasstrtod.c: switch on gethex(...) & STRTOG_Retmask rather than just on 376219422Sdasgethex(), and only copybits(..., bb) when bb is nonzero. This 377219422Sdasmattered for underflows and overflows in 0x notation. 378219422Sdas 379219422SdasThu Mar 25 22:34:56 MST 2004 380219422Sdas dtoa.c and gdtoa.c/misc.c: change "(!x & 1)" to "(!x)" to avoid 381219422Sdasconfusion by human readers -- the object code is unaffected (with 382219422Sdasreasonable compilers). 383219422Sdas 384219422SdasMon Apr 12 00:44:22 MDT 2004 385219422Sdas dtoa.c and gdtoa.tar.gz: update contact info. for dmg and correct 386219422Sdaspage numbers in comment on Steele & White (1990). 387219422Sdas gdtoa.tgz: add strtodnrp.c for a variant of strtod that is slower 388219422Sdasbut does not require 53-bit rounding precision on Intel IA32 systems. 389219422Sdas 390219422SdasTue Apr 13 00:28:14 MDT 2004 391219422Sdas gdtoa.tgz: strtod.c: fix glitch when both INFNAN_CHECK and No_Hex_NaN 392219422Sdasare #defined. Thanks to David Mendenhall for pointing this bug out. 393219422Sdas 394219422SdasWed Jan 5 22:39:17 MST 2005 395219422Sdas gdtoa.tgz: 396219422Sdas gethex.c: fix the bug reported by Stefan Farfeleder of ignoring a 397219422Sdasbinary-exponent-part if the converted number is zero. 398219422Sdas strto[pr]x.c: fix bug reported by Stefan Farfeleder in setting the 399219422Sdasexponent of denormals (which should be 0, not 1). 400219422Sdas g_xfmt.c: fix a corresponding bug with denormals. 401219422Sdas strtodg.c: fix a bug under IBM (base 16) arithemtic reported 402219422Sdasby Greg Alexander: a correction to the binary exponent for changes to 403219422Sdasthe exponent of a native double value for avoiding overflow had to be 404219422Sdasmultiplied by 4 ("e2 <<= 2;"). 405219422Sdas Various files: minor tweaks for portability. 406219422Sdas 407219422SdasSat Jan 15 15:36:03 MST 2005 408219422Sdas gdtoa.tgz: gethex.c: fix a glitch introduced last week (and reported 409219422Sdasby Stefan Farfelder) with 0x forms with no nonzero digits before the "." 410219422Sdascharacter, e.g., 0x.1 (which was rendered as 0 rather than .0625). 411219422Sdas gdtoa.tgz: many files: add automatic computation of gd_qnan.h for 412219422Sdasgiving the system-dependent format of a quiet NaN (the one generated 413219422Sdasfor Infinity - Infinity). Tweak test/makefile so differences in the 414219422Sdasspelling of Infinity ("INF" or "Inf" on some systems) do not matter. 415219422SdasFix bug in strtod.c and strtodg.c under which, e.g., -.nan was read 416219422Sdasas NaN rather than unacceptable input (causing return 0). Adjust 417219422Sdascomments in README about nan(...). Fix glitch in test/dt.c. 418219422Sdas 419219422SdasSun Jan 16 18:22:13 MST 2005 420219422Sdas gdtoa.tgz: strtodg.c: fix long-standing bug in handling input 421219422Sdasthat rounds up to 2^nbits, e.g., strtof("16777215.5"). Thanks to 422219422SdasEdward Moy for reporting this problem. 423219422Sdas gdtoa.tgz: Fix some bugs with -DJust_16. 424219422Sdas 425219422SdasThu Sep 22 22:40:16 MDT 2005 426219422Sdasgdtoa.tgz: 427219422Sdas strtod.c: unless prevented by -DNO_FENV_H, include C99's fenv.h 428219422Sdasand with hex input, get the current rounding mode from fegetround(). 429219422SdasWith decimal input, strtod honors the rounding mode automatically. 430219422SdasThanks to David Schultz (das at FreeBSD dot ORG) for pointing 431219422Sdas strtodg.c: fix a bug with handling numbers very near the largest 432219422Sdaspossible one, which were sometimes incorrectly converted to Infinity. 433219422SdasThanks to Edward Moy (emoy at apple dot com) for pointing this out. 434219422Sdas g_Qfmt.c: change strcpy to strcp. Thanks to J. T. Conklin 435219422Sdas(jtc at acorntoolworks dot com) for pointing this out. 436219422Sdas test/xtest.c: fix some subscript bugs. 437219422Sdas test/x.ou0, test/x.ou1, test/xL.: update in response to the above fix to 438219422Sdastest/xtest.c. 439219422Sdas test/makefile: add -lm to some link lines (needed for fegetround). 440219422Sdas 441219422SdasSun Jan 21 20:26:44 MST 2007 442219422Sdasgdtoa.tgz: 443219422Sdas strtodg.c: fix a botch in the test of whether to increase rvbits 444219422Sdasbefore terminating the big for(;;) loop with dsign true: change 445219422Sdas if (hi0bits(rvb->x[(rvb->wds - 1) >> kshift]) 446219422Sdas != j) 447219422Sdas rvbits++; 448219422Sdasto 449219422Sdas if (hi0bits(rvb->x[rvb->wds - 1]) != j) 450219422Sdas rvbits++; 451219422SdasExample of input where this bug bit: 1.9e27. Thanks to Edward Moy 452219422Sdas<emoy@apple.com> for providing this example. Also, simplify the 453219422Sdaspreceding computation of j. 454219422Sdas test/README: add comment that strtodt needs to operate with 53-bit 455219422Sdasrounding precision on Intel x86 systems, and add a pointer to Paxson's 456219422Sdaspaper. 457219422Sdas 458219422SdasSat Mar 15 11:44:31 MDT 2008 459219422Sdas dtoa.c and gdtoa.tgz: with -DINFNAN_CHECK and without 460219422Sdas-DGDOTA_NON_PEDANTIC_NANCHECK, conform to the ill-advised prescription 461219422Sdasin the C99 standard of consuming (...) in "nan(...)" even when ... 462219422Sdasis not of the expected form. Allow an optional 0x or 0X to precede 463219422Sdasthe string of hex digits in the expected form of ... . 464219422Sdas gdtoa.tgz: gethex.c: have, e.g., strtod("0xyz",&se) set se to "xyz". 465219422SdasPreviously it was incorrectly set to "0xyz". 466219422Sdas 467219422SdasThu Aug 28 22:37:35 MDT 2008 468219422Sdas dtoa.c and gdtoa.tgz: Fix a bug in strtod when compiled with 469219422Sdas-DHonor_FLT_ROUNDS: in rounding modes other than "to nearest", 470219422Sdasstrtod looped on input larger than and within a factor of 2 of 471219422Sdasthe largest finite floating-point number. Since FLT_ROUNDS is buggy 472219422Sdason some (Linux) systems in that it does not reflect calls on 473219422Sdasfesetround(), when Honor_FLT_ROUNDS is #defined, get the curren 474219422Sdasrounding mode from fegetround() rather than FLT_ROUNDS, unless 475219422SdasTrust_FLT_ROUNDS is also #defined. 476219422Sdas gdtoa/test/getround.c in gdtoa.tgz: simply report the current 477219422Sdasrounding mode when the input line is "r" by itself. (Previously it 478219422Sdasdid so, but also complained of invalid input.) 479219422Sdas gdtoa/gethex.c: fix an off-by-one bug in a rounding test; detect and 480219422Sdasdeal with huge exponents (positive or negative). This affected the 481219422Sdasreading of hexadecimal floating-point values (0x...). Also set errno 482219422Sdasto ERANGE on out-of-range values (unless compiled with -DNO_ERRNO). 483219422Sdas gdtoa/strtod.c: adjust scaling of tinytens[4] (as in dtoa.c) to 484219422Sdasavoid double rounding when dealing with numbers near the bottom of 485219422Sdasthe exponent range. 486219422Sdas 487219422SdasSat Aug 30 23:37:07 MDT 2008 488219422Sdas gdtoa/gethex.c: ensure *bp is set to something (NULL if nothing else). 489219422Sdas Bring gdtoa/xsum0.out and gdtoa/test/xsum0.out up to date. 490219422Sdas 491219422SdasTue Sep 9 22:08:30 MDT 2008 492219422Sdas gdtoa/strto*.c and gdtoa/*fmt.c: if compiled with -DUSE_LOCALE, use 493219422Sdasthe current locale's decimal point character string. 494219422Sdas gdtoa/gdtoa.c: trim trailing zeros in a missed case (e.g., ndigits = 6 495219422Sdason 1020302). 496219422Sdas dtoa.c and gdtoa/strtod.c: on systems with IEEE arithmetic (and without 497219422SdasNO_ERRNO being defined) set ERANGE for denormal values as well as real 498219422Sdasunderflows. 499219422Sdas gdtoa/strtodg.c: fix an off-by-one bug in rounding to the largest 500219422Sdasrepresentable magnitude when nbits is a multiple of 32. 501219422Sdas gdtoa/*fmt.c and gdtoa/gdtoa.h: bufsize changed from unsigned to size_t. 502219422Sdas gdtoaimp.h, *fmt.c: change in calling sequence to internal g__fmt(), 503219422Sdaswhich now explicitly checks bufsize. 504219422Sdas Relevant routines (see README) honor the current rounding mode if 505219422Sdascompiled with -DHonor_FLT_ROUNDS on IEEE-arithmetic systems that provide 506219422Sdasthe C99 fegetround() function. 507219422Sdas gdtoa/test/getround.c can optionally be compiled with 508219422Sdas-DHonor_FLT_ROUNDS and/or -DUSE_MY_LOCALE for manual testing of gdtoa.a 509219422Sdascompiled with -DHonor_FLT_ROUNDS or -DUSE_LOCALE. 510219422Sdas 511219422SdasFri Oct 10 20:07:15 MDT 2008 512219422Sdas gdtoa/gethex.c: fix a bug reading hexadecimal floating-point values 513219422Sdasstarting with "0xd" for a nonzero digit d (such as "0x1.0002p3"). The 514219422Sdasbug caused the values to be read as zero with endptr set incorrectly. 515219422Sdas 516219422SdasTue Oct 28 00:14:08 MDT 2008 517219422Sdas gdtoa/strtod.c: fix a comment glitch (with commented {}). 518219422Sdas 519219422SdasTue Nov 11 23:05:25 MST 2008 520219422Sdas gdtoa: fix a glitch in the strto* routines when compiled with 521219422Sdas-DUSE_LOCALE and the locale's decimal-point string is two or more 522219422Sdascharacters long. Wrong conversions were then possible. 523219422Sdas 524219422SdasFri Dec 5 18:20:36 MST 2008 525219422Sdas gdtoa.tgz: fix bugs with reading C99-style hexadecimal floating-point 526219422Sdasvalues when compiled with -DPack_16; on IEEE-arithmetic systems, make 527219422SdasINFNAN_CHECK the default unless NO_INFNAN_CHECK is #defined. (This is 528219422Sdasconsistent with dtoa.c, which has worked this way for a while.) 529219422Sdas dtoa.c: add recognition of C99-style hexadecimal floating-point 530219422Sdasvalues (unless compiled with NO_HEX_FP is #defined). 531219422Sdas 532219422SdasThu Dec 11 23:10:23 MST 2008 533219422Sdas dtoa.c: omit an unused variable. 534219422Sdas 535219422SdasFri Jan 2 22:45:33 MST 2009 536219422Sdas dtoa.c: tweak to banish some compiler warnings. 537219422Sdas 538219422SdasSun Mar 1 20:57:22 MST 2009 539219422Sdas dtoa.c, gdtoa/{g__fmt.c, gethex.c, strtod.c, strtodg.c}: change malloc 540219422Sdasto MALLOC. 541219422Sdas dtoa.c and gdtoa/gdtoaimp.h and gdtoa/misc.c: reduce Kmax, and use 542219422SdasMALLOC and FREE or free for huge blocks, which are possible only in 543219422Sdaspathological cases, such as dtoa calls in mode 3 with thousands of 544219422Sdasdigits requested, or strtod() calls with thousand of digits. For the 545219422Sdaslatter case, I have an alternate approach that runs much faster 546219422Sdasand uses less memory, but finding time to get it ready for distribution 547219422Sdasmay take a while. 548219422Sdas 549219422SdasMon Mar 16 00:32:43 MDT 2009 550219422Sdas dtoa.c: Fix a bug under -DUSE_LOCALE in handling "decimal point" 551219422Sdasstrings more than one character long. 552219422Sdas dtoa.c and gdtoa/misc.c: Remove a buggy test activated with 553219422Sdas-DDEBUG. 554219422Sdas dtoa.c and gdtoa/gdtoa.c: simplify logic for "4 leading 0 bits". 555219422Sdas dtoa.c: Add logic (that can be disabled with -DNO_STRTOD_BIGCOMP 556219422Sdasand that) to strtod for more efficiently handling a very long input 557219422Sdasstring. It proceeds by initially truncating the input string, then if 558219422Sdasnecessary comparing the whole string with a decimal expansion to 559219422Sdasdecide close cases. This logic is only used for input more than 560219422SdasSTRTOD_DIGLIM digits long (default 40), and for now only applies to 561219422SdasIEEE arithmetic (for want of other kinds of platforms on which to run 562219422Sdastests). This only appears worthwhile for absurdly long input strings, 563219422Sdasso a corresponding update to gdtoa does not seem warranted. 564219422Sdas dtoa.c, gdtoa.tgz: tweaks (mostly adding unnecessary parens) to 565219422Sdassilence "gcc -Wall" warnings. Aside from a couple of minor changes 566219422Sdasto banish erroneous warnings about uninitialized variables, the tweaks 567219422Sdasdo not affect the generated object code. 568219422Sdas 569219422SdasSat Apr 11 23:25:58 MDT 2009 570219422Sdas dtoa.c: fix glitch in compiling with -DNo_Hex_NaN and the bug of 571219422Sdasaccepting (e.g.) ".nan" or ".inf" as NaN or Infinity. 572219422Sdas gdtoa.tgz: tweaks to silence warnings from "gcc -Wstrict-aliasing=2"; 573219422Sdasupdate xsum0.out files. 574219422Sdas 575219422SdasSun Apr 19 23:40:24 MDT 2009 576219422Sdas dtoa.c, gdtoa/misc.c: do not attempt to allocate large memory blocks 577219422Sdasfrom the private memory pool (which was an unlikely event, but a bug). 578219422Sdas gdtoa/strtopx.c, gdtoa/strtopxL.c, gdtoa/strtorx.c, gdtoa/strtorxL.c: 579219422Sdassupply explicit bit for Infinity. Note that the Q routines (which do 580219422Sdasnot supply this bit) are appropriate for Sparc quad precision (probably 581219422Sdasknown as long double with most current compilers). 582219422Sdas 583219422SdasWed Dec 9 08:14:52 MST 2009 584219422Sdas gdtoa.tgz: add gdtoa/printf.c* and modify makefile so "make Printf" 585219422Sdasadds a printf to gdtoa.a (to be accessed with #include "stdio1.h" to 586219422Sdasget gdtoa/stdio1.h, which you might install in some standard place). 587219422SdasOn Intel/AMD i386, x86_64, and Sparc systems, this adds formats %La, 588219422Sdas%Le, %Lf and %Lg to handle long double. On x86_64 systems, it also 589219422Sdasadds %Lqa, %Lqe, %Lqf and %Lqg to handle 128-bit bit types (called 590219422Sdas__float128 by gcc and _Quad by the Intel compiler). In gdtoa/test, 591219422Sdas"make pf_test" tests this printf (provided the system is an i386, 592219422Sdasx86_64, or Sparc system). On x86_64 systems, "make pf_testLq" tests 593219422Sdasthe %Lq... formats (briefly). 594219422Sdas 595219422SdasMon Jan 11 22:25:17 MST 2010 596219422Sdas dtoa.c: fix a minor performance bug and, under compilation with -DDEBUG, 597219422Sdasan erroneous error message "oversize b in quorem" in strtod's processing 598219422Sdasof some input that underflows to zero. Also fix a bug in bigcomp()'s 599219422Sdashandling of numbers that will scale to denormal values. The increments 600219422Sdasthat bigcomp applied were ignoring the effects of denormalization. 601219422Sdas 602219422SdasSat Jan 23 00:25:54 MST 2010 603219422Sdas dtoa.c: Fix some glitches in recently introduced changes meant to 604219422Sdasspeed up returns in pedantic cases. In quorem, adjust #ifdef DEBUG 605219422Sdasstuff so it does not complain when bigcomp() calls quorem on input 606219422Sdasnear the smallest representable number and rounding up by a bit causes 607219422Sdasa quorem return > 9 (which in this case is not a bug). Fix a memory 608219422Sdasleak in the unlikely case of overflow only being detected after some 609219422Sdashigh-precision integer computations. Fix an off-by-one bug in 610219422Sdashandling a large number of digits with a few nonzero digits, followed 611219422Sdasby many zeros, and then some nonzero digits. (This does not happen 612219422Sdaswith sensible input.) Fix an off-by-one bug in a recently introduced 613219422Sdasquick test for underflow (i.e., zero result) on input at the bottom of 614219422Sdasthe exponent range. Thanks to Mark Dickinson for pointing these bugs 615219422Sdasout. 616219422Sdas 617219422Sdas dtoa.c and gdtoa/strtod.c: Fix an obscure bug in strtod's handling 618219422Sdasof some inputs of many digits at the bottom of the exponent range: 619219422Sdasresults were sometimes off by a bit when gdtoa/strtod.c or dtoa.c was 620219422Sdascompiled without -DNO_IEEE_SCALE and, for dtoa.c, when compiled with 621219422Sdas-DNO_STRTOD_BIGCOMP. 622219422Sdas 623219422Sdas gdtoa/test/testnos3: add some examples that went wrong before 624219422Sdasthe present changes. 625219422Sdas 626219422SdasSat Jan 23 23:29:02 MST 2010 627219422Sdas dtoa.c: more tweaks relevant only to absurd input. 628219422Sdas 629219422SdasTue Feb 2 23:05:34 MST 2010 630219422Sdas dtoa.c: add test for setting errno = ERANGE when input of many digits 631219422Sdasis rounded to Infinity or underflows to zero. Fix a memory leak in 632219422Sdassuch instances. 633219422Sdas gdtoa/strtod.c: make some corresponding changes. 634219422Sdas 635219422SdasWed Jul 7 09:25:46 MDT 2010 636219422Sdas dtoa.c: adjust to use bigcomp when necessary when compiled with 637219422Sdas-DHonor_FLT_ROUNDS (and without -DNO_STRTOD_BIGCOMP), and the rounding 638219422Sdasmode is torwards +Infinity. An input (supplied by Rick Regan 639219422Sdas<exploringbinary@gmail.com>) where this matters is 640219422Sdas1.100000000000000088817841970012523233890533447265626 641219422Sdas gdtoa/strtod.c: fix errors (introduced 20090411) when compiled 642219422Sdaswith -DHonor_FLT_ROUNDS. 643219422Sdas 644219422SdasWed Sep 15 09:00:26 MDT 2010 645219422Sdas dtoa.c, gdtoa/dtoa.c, gdtoa/gdtoa.c: fix bugs with -DROUND_BIASED 646219422Sdaspointed out by Jay Foad. 647219422Sdas 648219422SdasMon Sep 27 13:43:30 MDT 2010 649219422Sdas gdtoa/gdtoa.c: fix a glitch (not revealed by compilation) in the 650219422Sdaschanges of 15 Sept. 2010. 651219422Sdas 652219422SdasFri Nov 5 13:02:41 MDT 2010 653219422Sdas dtoa.c: fix a bug related to bigcomp: decimal strings with all 654219422Sdaszeros before the decimal point more than 40 significant digits that 655219422Sdasrequired use of bigcomp might be converted very incorrectly. 656219422SdasExample: .010000000000000000057612911342378542997169 . 657219422SdasThanks to Rick Regan <exploringbinary@gmail.com> for reporting the 658219422Sdassymptoms and providing an example. 659219422Sdas 660219422Sdas20110403: 661219422Sdas dtoa.c, gdtoa/gdtoaimp.h, gdtoa/strtod.c: if 662219422SdasROUND_BIASED_without_Round_Up is #defined, assume ROUND_BIASED and 663219422Sdasomit the quick computation that would use ordinary arithmetic to 664219422Sdascompute the correctly rounded result with one rounding error. If you 665219422Sdaswant biased rounding with IEEE-style format "double" and will operate 666219422Sdaswith rounding toward +Infinity, it suffices to #define ROUND_BIASED 667219422Sdas(and thus retain the quick computation when it is appropriate). 668219422Sdas gdtoa/gdtoa.h: change default Long from long to int (with the goal 669219422Sdasof portability when compiling without -DLong=... specified). On some 670219422Sdas64-bit systems, long is a 64-bit type; we need a 32-bit type here. 671219422Sdas dtoa.c, gdtoa/gdtoa.c: fix a glith with ndigits with mode = 4 at 672219422Sdasthe bottom of the exponent range, e.g., 1e-323. 673