xref: /minix3/lib/libc/gdtoa/README (revision f14fb602092e015ff630df58e17c2a9cd57d29b3)
12fe8fb19SBen GrasThis directory contains source for a library of binary -> decimal
22fe8fb19SBen Grasand decimal -> binary conversion routines, for single-, double-,
32fe8fb19SBen Grasand extended-precision IEEE binary floating-point arithmetic, and
42fe8fb19SBen Grasother IEEE-like binary floating-point, including "double double",
52fe8fb19SBen Grasas in
62fe8fb19SBen Gras
72fe8fb19SBen Gras	T. J. Dekker, "A Floating-Point Technique for Extending the
82fe8fb19SBen Gras	Available Precision", Numer. Math. 18 (1971), pp. 224-242
92fe8fb19SBen Gras
102fe8fb19SBen Grasand
112fe8fb19SBen Gras
122fe8fb19SBen Gras	"Inside Macintosh: PowerPC Numerics", Addison-Wesley, 1994
132fe8fb19SBen Gras
142fe8fb19SBen GrasThe conversion routines use double-precision floating-point arithmetic
152fe8fb19SBen Grasand, where necessary, high precision integer arithmetic.  The routines
162fe8fb19SBen Grasare generalizations of the strtod and dtoa routines described in
172fe8fb19SBen Gras
182fe8fb19SBen Gras	David M. Gay, "Correctly Rounded Binary-Decimal and
192fe8fb19SBen Gras	Decimal-Binary Conversions", Numerical Analysis Manuscript
202fe8fb19SBen Gras	No. 90-10, Bell Labs, Murray Hill, 1990;
212fe8fb19SBen Gras	http://cm.bell-labs.com/cm/cs/what/ampl/REFS/rounding.ps.gz
222fe8fb19SBen Gras
232fe8fb19SBen Gras(based in part on papers by Clinger and Steele & White: see the
242fe8fb19SBen Grasreferences in the above paper).
252fe8fb19SBen Gras
262fe8fb19SBen GrasThe present conversion routines should be able to use any of IEEE binary,
272fe8fb19SBen GrasVAX, or IBM-mainframe double-precision arithmetic internally, but I (dmg)
282fe8fb19SBen Grashave so far only had a chance to test them with IEEE double precision
292fe8fb19SBen Grasarithmetic.
302fe8fb19SBen Gras
312fe8fb19SBen GrasThe core conversion routines are strtodg for decimal -> binary conversions
322fe8fb19SBen Grasand gdtoa for binary -> decimal conversions.  These routines operate
332fe8fb19SBen Grason arrays of unsigned 32-bit integers of type ULong, a signed 32-bit
342fe8fb19SBen Grasexponent of type Long, and arithmetic characteristics described in
352fe8fb19SBen Grasstruct FPI; FPI, Long, and ULong are defined in gdtoa.h.  File arith.h
362fe8fb19SBen Grasis supposed to provide #defines that cause gdtoa.h to define its
372fe8fb19SBen Grastypes correctly.  File arithchk.c is source for a program that
382fe8fb19SBen Grasgenerates a suitable arith.h on all systems where I've been able to
392fe8fb19SBen Grastest it.
402fe8fb19SBen Gras
412fe8fb19SBen GrasThe core conversion routines are meant to be called by helper routines
422fe8fb19SBen Grasthat know details of the particular binary arithmetic of interest and
432fe8fb19SBen Grasconvert.  The present directory provides helper routines for 5 variants
442fe8fb19SBen Grasof IEEE binary floating-point arithmetic, each indicated by one or
452fe8fb19SBen Grastwo letters:
462fe8fb19SBen Gras
472fe8fb19SBen Gras	f	IEEE single precision
482fe8fb19SBen Gras	d	IEEE double precision
492fe8fb19SBen Gras	x	IEEE extended precision, as on Intel 80x87
502fe8fb19SBen Gras		and software emulations of Motorola 68xxx chips
512fe8fb19SBen Gras		that do not pad the way the 68xxx does, but
522fe8fb19SBen Gras		only store 80 bits
532fe8fb19SBen Gras	xL	IEEE extended precision, as on Motorola 68xxx chips
542fe8fb19SBen Gras	Q	quad precision, as on Sun Sparc chips
552fe8fb19SBen Gras	dd	double double, pairs of IEEE double numbers
562fe8fb19SBen Gras		whose sum is the desired value
572fe8fb19SBen Gras
582fe8fb19SBen GrasFor decimal -> binary conversions, there are three families of
59*f14fb602SLionel Sambuchelper routines: one for round-nearest (or the current rounding
60*f14fb602SLionel Sambucmode on IEEE-arithmetic systems that provide the C99 fegetround()
61*f14fb602SLionel Sambucfunction, if compiled with -DHonor_FLT_ROUNDS):
622fe8fb19SBen Gras
632fe8fb19SBen Gras	strtof
642fe8fb19SBen Gras	strtod
652fe8fb19SBen Gras	strtodd
662fe8fb19SBen Gras	strtopd
672fe8fb19SBen Gras	strtopf
682fe8fb19SBen Gras	strtopx
692fe8fb19SBen Gras	strtopxL
702fe8fb19SBen Gras	strtopQ
712fe8fb19SBen Gras
722fe8fb19SBen Grasone with rounding direction specified:
732fe8fb19SBen Gras
742fe8fb19SBen Gras	strtorf
752fe8fb19SBen Gras	strtord
762fe8fb19SBen Gras	strtordd
772fe8fb19SBen Gras	strtorx
782fe8fb19SBen Gras	strtorxL
792fe8fb19SBen Gras	strtorQ
802fe8fb19SBen Gras
812fe8fb19SBen Grasand one for computing an interval (at most one bit wide) that contains
822fe8fb19SBen Grasthe decimal number:
832fe8fb19SBen Gras
842fe8fb19SBen Gras	strtoIf
852fe8fb19SBen Gras	strtoId
862fe8fb19SBen Gras	strtoIdd
872fe8fb19SBen Gras	strtoIx
882fe8fb19SBen Gras	strtoIxL
892fe8fb19SBen Gras	strtoIQ
902fe8fb19SBen Gras
912fe8fb19SBen GrasThe latter call strtoIg, which makes one call on strtodg and adjusts
922fe8fb19SBen Grasthe result to provide the desired interval.  On systems where native
932fe8fb19SBen Grasarithmetic can easily make one-ulp adjustments on values in the
942fe8fb19SBen Grasdesired floating-point format, it might be more efficient to use the
952fe8fb19SBen Grasnative arithmetic.  Routine strtodI is a variant of strtoId that
962fe8fb19SBen Grasillustrates one way to do this for IEEE binary double-precision
972fe8fb19SBen Grasarithmetic -- but whether this is more efficient remains to be seen.
982fe8fb19SBen Gras
992fe8fb19SBen GrasFunctions strtod and strtof have "natural" return types, float and
1002fe8fb19SBen Grasdouble -- strtod is specified by the C standard, and strtof appears
1012fe8fb19SBen Grasin the stdlib.h of some systems, such as (at least some) Linux systems.
1022fe8fb19SBen GrasThe other functions write their results to their final argument(s):
1032fe8fb19SBen Grasto the final two argument for the strtoI... (interval) functions,
1042fe8fb19SBen Grasand to the final argument for the others (strtop... and strtor...).
1052fe8fb19SBen GrasWhere possible, these arguments have "natural" return types (double*
1062fe8fb19SBen Grasor float*), to permit at least some type checking.  In reality, they
1072fe8fb19SBen Grasare viewed as arrays of ULong (or, for the "x" functions, UShort)
1082fe8fb19SBen Grasvalues. On systems where long double is the appropriate type, one can
1092fe8fb19SBen Graspass long double* final argument(s) to these routines.  The int value
1102fe8fb19SBen Grasthat these routines return is the return value from the call they make
1112fe8fb19SBen Grason strtodg; see the enum of possible return values in gdtoa.h.
1122fe8fb19SBen Gras
1132fe8fb19SBen GrasSource files g_ddfmt.c, misc.c, smisc.c, strtod.c, strtodg.c, and ulp.c
1142fe8fb19SBen Grasshould use true IEEE double arithmetic (not, e.g., double extended),
1152fe8fb19SBen Grasat least for storing (and viewing the bits of) the variables declared
1162fe8fb19SBen Gras"double" within them.
1172fe8fb19SBen Gras
1182fe8fb19SBen GrasOne detail indicated in struct FPI is whether the target binary
1192fe8fb19SBen Grasarithmetic departs from the IEEE standard by flushing denormalized
1202fe8fb19SBen Grasnumbers to 0.  On systems that do this, the helper routines for
1212fe8fb19SBen Grasconversion to double-double format (when compiled with
1222fe8fb19SBen GrasSudden_Underflow #defined) penalize the bottom of the exponent
1232fe8fb19SBen Grasrange so that they return a nonzero result only when the least
1242fe8fb19SBen Grassignificant bit of the less significant member of the pair of
1252fe8fb19SBen Grasdouble values returned can be expressed as a normalized double
1262fe8fb19SBen Grasvalue.  An alternative would be to drop to 53-bit precision near
1272fe8fb19SBen Grasthe bottom of the exponent range.  To get correct rounding, this
1282fe8fb19SBen Graswould (in general) require two calls on strtodg (one specifying
1292fe8fb19SBen Gras126-bit arithmetic, then, if necessary, one specifying 53-bit
1302fe8fb19SBen Grasarithmetic).
1312fe8fb19SBen Gras
1322fe8fb19SBen GrasBy default, the core routine strtodg and strtod set errno to ERANGE
1332fe8fb19SBen Grasif the result overflows to +Infinity or underflows to 0.  Compile
1342fe8fb19SBen Grasthese routines with NO_ERRNO #defined to inhibit errno assignments.
1352fe8fb19SBen Gras
1362fe8fb19SBen GrasRoutine strtod is based on netlib's "dtoa.c from fp", and
1372fe8fb19SBen Gras(f = strtod(s,se)) is more efficient for some conversions than, say,
1382fe8fb19SBen Grasstrtord(s,se,1,&f).  Parts of strtod require true IEEE double
1392fe8fb19SBen Grasarithmetic with the default rounding mode (round-to-nearest) and, on
1402fe8fb19SBen Grassystems with IEEE extended-precision registers, double-precision
1412fe8fb19SBen Gras(53-bit) rounding precision.  If the machine uses (the equivalent of)
1422fe8fb19SBen GrasIntel 80x87 arithmetic, the call
1432fe8fb19SBen Gras	_control87(PC_53, MCW_PC);
1442fe8fb19SBen Grasdoes this with many compilers.  Whether this or another call is
1452fe8fb19SBen Grasappropriate depends on the compiler; for this to work, it may be
1462fe8fb19SBen Grasnecessary to #include "float.h" or another system-dependent header
1472fe8fb19SBen Grasfile.
1482fe8fb19SBen Gras
1492fe8fb19SBen GrasSource file strtodnrp.c gives a strtod that does not require 53-bit
1502fe8fb19SBen Grasrounding precision on systems (such as Intel IA32 systems) that may
1512fe8fb19SBen Grassuffer double rounding due to use of extended-precision registers.
1522fe8fb19SBen GrasFor some conversions this variant of strtod is less efficient than the
1532fe8fb19SBen Grasone in strtod.c when the latter is run with 53-bit rounding precision.
1542fe8fb19SBen Gras
1552fe8fb19SBen GrasThe values that the strto* routines return for NaNs are determined by
1562fe8fb19SBen Grasgd_qnan.h, which the makefile generates by running the program whose
1572fe8fb19SBen Grassource is qnan.c.  Note that the rules for distinguishing signaling
1582fe8fb19SBen Grasfrom quiet NaNs are system-dependent.  For cross-compilation, you need
1592fe8fb19SBen Grasto determine arith.h and gd_qnan.h suitably, e.g., using the
1602fe8fb19SBen Grasarithmetic of the target machine.
1612fe8fb19SBen Gras
1622fe8fb19SBen GrasC99's hexadecimal floating-point constants are recognized by the
1632fe8fb19SBen Grasstrto* routines (but this feature has not yet been heavily tested).
1642fe8fb19SBen GrasCompiling with NO_HEX_FP #defined disables this feature.
1652fe8fb19SBen Gras
1662fe8fb19SBen GrasWhen compiled with -DINFNAN_CHECK, the strto* routines recognize C99's
1672fe8fb19SBen GrasNaN and Infinity syntax.  Moreover, unless No_Hex_NaN is #defined, the
1682fe8fb19SBen Grasstrto* routines also recognize C99's NaN(...) syntax: they accept
1692fe8fb19SBen Gras(case insensitively) strings of the form NaN(x), where x is a string
1702fe8fb19SBen Grasof hexadecimal digits and spaces; if there is only one string of
1712fe8fb19SBen Grashexadecimal digits, it is taken for the fraction bits of the resulting
1722fe8fb19SBen GrasNaN; if there are two or more strings of hexadecimal digits, each
1732fe8fb19SBen Grasstring is assigned to the next available sequence of 32-bit words of
1742fe8fb19SBen Grasfractions bits (starting with the most significant), right-aligned in
1752fe8fb19SBen Graseach sequence.
1762fe8fb19SBen Gras
1772fe8fb19SBen GrasFor binary -> decimal conversions, I've provided just one family
1782fe8fb19SBen Grasof helper routines:
1792fe8fb19SBen Gras
1802fe8fb19SBen Gras	g_ffmt
1812fe8fb19SBen Gras	g_dfmt
1822fe8fb19SBen Gras	g_ddfmt
1832fe8fb19SBen Gras	g_xfmt
1842fe8fb19SBen Gras	g_xLfmt
1852fe8fb19SBen Gras	g_Qfmt
1862fe8fb19SBen Gras
1872fe8fb19SBen Graswhich do a "%g" style conversion either to a specified number of decimal
1882fe8fb19SBen Grasplaces (if their ndig argument is positive), or to the shortest
1892fe8fb19SBen Grasdecimal string that rounds to the given binary floating-point value
1902fe8fb19SBen Gras(if ndig <= 0).  They write into a buffer supplied as an argument
1912fe8fb19SBen Grasand return either a pointer to the end of the string (a null character)
1922fe8fb19SBen Grasin the buffer, if the buffer was long enough, or 0.  Other forms of
1932fe8fb19SBen Grasconversion are easily done with the help of gdtoa(), such as %e or %f
1942fe8fb19SBen Grasstyle and conversions with direction of rounding specified (so that, if
1952fe8fb19SBen Grasdesired, the decimal value is either >= or <= the binary value).
196*f14fb602SLionel SambucOn IEEE-arithmetic systems that provide the C99 fegetround() function,
197*f14fb602SLionel Sambucif compiled with -DHonor_FLT_ROUNDS, these routines honor the current
198*f14fb602SLionel Sambucrounding mode.
1992fe8fb19SBen Gras
2002fe8fb19SBen GrasFor an example of more general conversions based on dtoa(), see
2012fe8fb19SBen Grasnetlib's "printf.c from ampl/solvers".
2022fe8fb19SBen Gras
2032fe8fb19SBen GrasFor double-double -> decimal, g_ddfmt() assumes IEEE-like arithmetic
2042fe8fb19SBen Grasof precision max(126, #bits(input)) bits, where #bits(input) is the
2052fe8fb19SBen Grasnumber of mantissa bits needed to represent the sum of the two double
2062fe8fb19SBen Grasvalues in the input.
2072fe8fb19SBen Gras
2082fe8fb19SBen GrasThe makefile creates a library, gdtoa.a.  To use the helper
2092fe8fb19SBen Grasroutines, a program only needs to include gdtoa.h.  All the
2102fe8fb19SBen Grassource files for gdtoa.a include a more extensive gdtoaimp.h;
2112fe8fb19SBen Grasamong other things, gdtoaimp.h has #defines that make "internal"
2122fe8fb19SBen Grasnames end in _D2A.  To make a "system" library, one could modify
2132fe8fb19SBen Grasthese #defines to make the names start with __.
2142fe8fb19SBen Gras
2152fe8fb19SBen GrasVarious comments about possible #defines appear in gdtoaimp.h,
2162fe8fb19SBen Grasbut for most purposes, arith.h should set suitable #defines.
2172fe8fb19SBen Gras
2182fe8fb19SBen GrasSystems with preemptive scheduling of multiple threads require some
2192fe8fb19SBen Grasmanual intervention.  On such systems, it's necessary to compile
2202fe8fb19SBen Grasdmisc.c, dtoa.c gdota.c, and misc.c with MULTIPLE_THREADS #defined,
2212fe8fb19SBen Grasand to provide (or suitably #define) two locks, acquired by
2222fe8fb19SBen GrasACQUIRE_DTOA_LOCK(n) and freed by FREE_DTOA_LOCK(n) for n = 0 or 1.
2232fe8fb19SBen Gras(The second lock, accessed in pow5mult, ensures lazy evaluation of
2242fe8fb19SBen Grasonly one copy of high powers of 5; omitting this lock would introduce
2252fe8fb19SBen Grasa small probability of wasting memory, but would otherwise be harmless.)
2262fe8fb19SBen GrasRoutines that call dtoa or gdtoa directly must also invoke freedtoa(s)
2272fe8fb19SBen Grasto free the value s returned by dtoa or gdtoa.  It's OK to do so whether
2282fe8fb19SBen Grasor not MULTIPLE_THREADS is #defined, and the helper g_*fmt routines
2292fe8fb19SBen Graslisted above all do this indirectly (in gfmt_D2A(), which they all call).
2302fe8fb19SBen Gras
2312fe8fb19SBen GrasBy default, there is a private pool of memory of length 2000 bytes
2322fe8fb19SBen Grasfor intermediate quantities, and MALLOC (see gdtoaimp.h) is called only
2332fe8fb19SBen Grasif the private pool does not suffice.   2000 is large enough that MALLOC
2342fe8fb19SBen Grasis called only under very unusual circumstances (decimal -> binary
2352fe8fb19SBen Grasconversion of very long strings) for conversions to and from double
2362fe8fb19SBen Grasprecision.  For systems with preemptively scheduled multiple threads
2372fe8fb19SBen Grasor for conversions to extended or quad, it may be appropriate to
2382fe8fb19SBen Gras#define PRIVATE_MEM nnnn, where nnnn is a suitable value > 2000.
2392fe8fb19SBen GrasFor extended and quad precisions, -DPRIVATE_MEM=20000 is probably
2402fe8fb19SBen Grasplenty even for many digits at the ends of the exponent range.
2412fe8fb19SBen GrasUse of the private pool avoids some overhead.
2422fe8fb19SBen Gras
2432fe8fb19SBen GrasDirectory test provides some test routines.  See its README.
2442fe8fb19SBen GrasI've also tested this stuff (except double double conversions)
2452fe8fb19SBen Graswith Vern Paxson's testbase program: see
2462fe8fb19SBen Gras
2472fe8fb19SBen Gras	V. Paxson and W. Kahan, "A Program for Testing IEEE Binary-Decimal
2482fe8fb19SBen Gras	Conversion", manuscript, May 1991,
2492fe8fb19SBen Gras	ftp://ftp.ee.lbl.gov/testbase-report.ps.Z .
2502fe8fb19SBen Gras
2512fe8fb19SBen Gras(The same ftp directory has source for testbase.)
2522fe8fb19SBen Gras
2532fe8fb19SBen GrasSome system-dependent additions to CFLAGS in the makefile:
2542fe8fb19SBen Gras
2552fe8fb19SBen Gras	HU-UX: -Aa -Ae
2562fe8fb19SBen Gras	OSF (DEC Unix): -ieee_with_no_inexact
2572fe8fb19SBen Gras	SunOS 4.1x: -DKR_headers -DBad_float_h
2582fe8fb19SBen Gras
2592fe8fb19SBen GrasIf you want to put this stuff into a shared library and your
2602fe8fb19SBen Grasoperating system requires export lists for shared libraries,
2612fe8fb19SBen Grasthe following would be an appropriate export list:
2622fe8fb19SBen Gras
2632fe8fb19SBen Gras	dtoa
2642fe8fb19SBen Gras	freedtoa
2652fe8fb19SBen Gras	g_Qfmt
2662fe8fb19SBen Gras	g_ddfmt
2672fe8fb19SBen Gras	g_dfmt
2682fe8fb19SBen Gras	g_ffmt
2692fe8fb19SBen Gras	g_xLfmt
2702fe8fb19SBen Gras	g_xfmt
2712fe8fb19SBen Gras	gdtoa
2722fe8fb19SBen Gras	strtoIQ
2732fe8fb19SBen Gras	strtoId
2742fe8fb19SBen Gras	strtoIdd
2752fe8fb19SBen Gras	strtoIf
2762fe8fb19SBen Gras	strtoIx
2772fe8fb19SBen Gras	strtoIxL
2782fe8fb19SBen Gras	strtod
2792fe8fb19SBen Gras	strtodI
2802fe8fb19SBen Gras	strtodg
2812fe8fb19SBen Gras	strtof
2822fe8fb19SBen Gras	strtopQ
2832fe8fb19SBen Gras	strtopd
2842fe8fb19SBen Gras	strtopdd
2852fe8fb19SBen Gras	strtopf
2862fe8fb19SBen Gras	strtopx
2872fe8fb19SBen Gras	strtopxL
2882fe8fb19SBen Gras	strtorQ
2892fe8fb19SBen Gras	strtord
2902fe8fb19SBen Gras	strtordd
2912fe8fb19SBen Gras	strtorf
2922fe8fb19SBen Gras	strtorx
2932fe8fb19SBen Gras	strtorxL
2942fe8fb19SBen Gras
2952fe8fb19SBen GrasWhen time permits, I (dmg) hope to write in more detail about the
2962fe8fb19SBen Graspresent conversion routines; for now, this README file must suffice.
2972fe8fb19SBen GrasMeanwhile, if you wish to write helper functions for other kinds of
2982fe8fb19SBen GrasIEEE-like arithmetic, some explanation of struct FPI and the bits
2992fe8fb19SBen Grasarray may be helpful.  Both gdtoa and strtodg operate on a bits array
3002fe8fb19SBen Grasdescribed by FPI *fpi.  The bits array is of type ULong, a 32-bit
3012fe8fb19SBen Grasunsigned integer type.  Floating-point numbers have fpi->nbits bits,
3022fe8fb19SBen Graswith the least significant 32 bits in bits[0], the next 32 bits in
3032fe8fb19SBen Grasbits[1], etc.  These numbers are regarded as integers multiplied by
3042fe8fb19SBen Gras2^e (i.e., 2 to the power of the exponent e), where e is the second
3052fe8fb19SBen Grasargument (be) to gdtoa and is stored in *exp by strtodg.  The minimum
3062fe8fb19SBen Grasand maximum exponent values fpi->emin and fpi->emax for normalized
3072fe8fb19SBen Grasfloating-point numbers reflect this arrangement.  For example, the
3082fe8fb19SBen GrasP754 standard for binary IEEE arithmetic specifies doubles as having
3092fe8fb19SBen Gras53 bits, with normalized values of the form 1.xxxxx... times 2^(b-1023),
3102fe8fb19SBen Graswith 52 bits (the x's) and the biased exponent b represented explicitly;
3112fe8fb19SBen Grasb is an unsigned integer in the range 1 <= b <= 2046 for normalized
3122fe8fb19SBen Grasfinite doubles, b = 0 for denormals, and b = 2047 for Infinities and NaNs.
3132fe8fb19SBen GrasTo turn an IEEE double into the representation used by strtodg and gdtoa,
3142fe8fb19SBen Graswe multiply 1.xxxx... by 2^52 (to make it an integer) and reduce the
3152fe8fb19SBen Grasexponent e = (b-1023) by 52:
3162fe8fb19SBen Gras
3172fe8fb19SBen Gras	fpi->emin = 1 - 1023 - 52
3182fe8fb19SBen Gras	fpi->emax = 1046 - 1023 - 52
3192fe8fb19SBen Gras
3202fe8fb19SBen GrasIn various wrappers for IEEE double, we actually write -53 + 1 rather
3212fe8fb19SBen Grasthan -52, to emphasize that there are 53 bits including one implicit bit.
3222fe8fb19SBen GrasField fpi->rounding indicates the desired rounding direction, with
3232fe8fb19SBen Graspossible values
3242fe8fb19SBen Gras	FPI_Round_zero = toward 0,
3252fe8fb19SBen Gras	FPI_Round_near = unbiased rounding -- the IEEE default,
3262fe8fb19SBen Gras	FPI_Round_up = toward +Infinity, and
3272fe8fb19SBen Gras	FPI_Round_down = toward -Infinity
3282fe8fb19SBen Grasgiven in gdtoa.h.
3292fe8fb19SBen Gras
3302fe8fb19SBen GrasField fpi->sudden_underflow indicates whether strtodg should return
3312fe8fb19SBen Grasdenormals or flush them to zero.  Normal floating-point numbers have
3322fe8fb19SBen Grasbit fpi->nbits in the bits array on.  Denormals have it off, with
3332fe8fb19SBen Grasexponent = fpi->emin.  Strtodg provides distinct return values for normals
3342fe8fb19SBen Grasand denormals; see gdtoa.h.
3352fe8fb19SBen Gras
3362fe8fb19SBen GrasCompiling g__fmt.c, strtod.c, and strtodg.c with -DUSE_LOCALE causes
3372fe8fb19SBen Grasthe decimal-point character to be taken from the current locale; otherwise
3382fe8fb19SBen Grasit is '.'.
3392fe8fb19SBen Gras
340*f14fb602SLionel SambucSource files dtoa.c and strtod.c in this directory are derived from
341*f14fb602SLionel Sambucnetlib's "dtoa.c from fp" and are meant to function equivalently.
342*f14fb602SLionel SambucWhen compiled with Honor_FLT_ROUNDS #defined (on systems that provide
343*f14fb602SLionel SambucFLT_ROUNDS and fegetround() as specified in the C99 standard), they
344*f14fb602SLionel Sambuchonor the current rounding mode.  Because FLT_ROUNDS is buggy on some
345*f14fb602SLionel Sambuc(Linux) systems -- not reflecting calls on fesetround(), as the C99
346*f14fb602SLionel Sambucstandard says it should -- when Honor_FLT_ROUNDS is #defined, the
347*f14fb602SLionel Sambuccurrent rounding mode is obtained from fegetround() rather than from
348*f14fb602SLionel SambucFLT_ROUNDS, unless Trust_FLT_ROUNDS is also #defined.
349*f14fb602SLionel Sambuc
350*f14fb602SLionel SambucCompile with -DUSE_LOCALE to use the current locale; otherwise
351*f14fb602SLionel Sambucdecimal points are assumed to be '.'.  With -DUSE_LOCALE, unless
352*f14fb602SLionel Sambucyou also compile with -DNO_LOCALE_CACHE, the details about the
353*f14fb602SLionel Sambuccurrent "decimal point" character string are cached and assumed not
354*f14fb602SLionel Sambucto change during the program's execution.
355*f14fb602SLionel Sambuc
356*f14fb602SLionel SambucOn machines with a 64-bit long double and perhaps a 113-bit "quad"
357*f14fb602SLionel Sambuctype, you can invoke "make Printf" to add Printf (and variants, such
358*f14fb602SLionel Sambucas Fprintf) to gdtoa.a.  These are analogs, declared in stdio1.h, of
359*f14fb602SLionel Sambucprintf and fprintf, etc. in which %La, %Le, %Lf, and %Lg are for long
360*f14fb602SLionel Sambucdouble and (if appropriate) %Lqa, %Lqe, %Lqf, and %Lqg are for quad
361*f14fb602SLionel Sambucprecision printing.
362*f14fb602SLionel Sambuc
3632fe8fb19SBen GrasPlease send comments to	David M. Gay (dmg at acm dot org, with " at "
3642fe8fb19SBen Graschanged at "@" and " dot " changed to ".").
365