Lines Matching +full:end +full:- +full:of +full:- +full:conversion
1 This directory contains source for a library of binary -> decimal
2 and decimal -> binary conversion routines, for single-, double-,
3 and extended-precision IEEE binary floating-point arithmetic, and
4 other IEEE-like binary floating-point, including "double double",
7 T. J. Dekker, "A Floating-Point Technique for Extending the
8 Available Precision", Numer. Math. 18 (1971), pp. 224-242
12 "Inside Macintosh: PowerPC Numerics", Addison-Wesley, 1994
14 The conversion routines use double-precision floating-point arithmetic
16 are generalizations of the strtod and dtoa routines described in
18 David M. Gay, "Correctly Rounded Binary-Decimal and
19 Decimal-Binary Conversions", Numerical Analysis Manuscript
20 No. 90-10, Bell Labs, Murray Hill, 1990;
21 http://cm.bell-labs.com/cm/cs/what/ampl/REFS/rounding.ps.gz
26 The present conversion routines should be able to use any of IEEE binary,
27 VAX, or IBM-mainframe double-precision arithmetic internally, but I (dmg)
31 The core conversion routines are strtodg for decimal -> binary conversions
32 and gdtoa for binary -> decimal conversions. These routines operate
33 on arrays of unsigned 32-bit integers of type ULong, a signed 32-bit
34 exponent of type Long, and arithmetic characteristics described in
41 The core conversion routines are meant to be called by helper routines
42 that know details of the particular binary arithmetic of interest and
44 of IEEE binary floating-point arithmetic, each indicated by one or
50 and software emulations of Motorola 68xxx chips
55 dd double double, pairs of IEEE double numbers
58 For decimal -> binary conversions, there are three families of
59 helper routines: one for round-nearest (or the current rounding
60 mode on IEEE-arithmetic systems that provide the C99 fegetround()
61 function, if compiled with -DHonor_FLT_ROUNDS):
93 arithmetic can easily make one-ulp adjustments on values in the
94 desired floating-point format, it might be more efficient to use the
95 native arithmetic. Routine strtodI is a variant of strtoId that
96 illustrates one way to do this for IEEE binary double-precision
97 arithmetic -- but whether this is more efficient remains to be seen.
100 double -- strtod is specified by the C standard, and strtof appears
101 in the stdlib.h of some systems, such as (at least some) Linux systems.
107 are viewed as arrays of ULong (or, for the "x" functions, UShort)
111 on strtodg; see the enum of possible return values in gdtoa.h.
115 at least for storing (and viewing the bits of) the variables declared
121 conversion to double-double format (when compiled with
122 Sudden_Underflow #defined) penalize the bottom of the exponent
124 significant bit of the less significant member of the pair of
126 value. An alternative would be to drop to 53-bit precision near
127 the bottom of the exponent range. To get correct rounding, this
129 126-bit arithmetic, then, if necessary, one specifying 53-bit
138 strtord(s,se,1,&f). Parts of strtod require true IEEE double
139 arithmetic with the default rounding mode (round-to-nearest) and, on
140 systems with IEEE extended-precision registers, double-precision
141 (53-bit) rounding precision. If the machine uses (the equivalent of)
146 necessary to #include "float.h" or another system-dependent header
149 Source file strtodnrp.c gives a strtod that does not require 53-bit
151 suffer double rounding due to use of extended-precision registers.
152 For some conversions this variant of strtod is less efficient than the
153 one in strtod.c when the latter is run with 53-bit rounding precision.
158 from quiet NaNs are system-dependent. For cross-compilation, you need
160 arithmetic of the target machine.
162 C99's hexadecimal floating-point constants are recognized by the
166 When compiled with -DINFNAN_CHECK, the strto* routines recognize C99's
169 (case insensitively) strings of the form NaN(x), where x is a string
170 of hexadecimal digits and spaces; if there is only one string of
171 hexadecimal digits, it is taken for the fraction bits of the resulting
172 NaN; if there are two or more strings of hexadecimal digits, each
173 string is assigned to the next available sequence of 32-bit words of
174 fractions bits (starting with the most significant), right-aligned in
177 For binary -> decimal conversions, I've provided just one family
178 of helper routines:
187 which do a "%g" style conversion either to a specified number of decimal
189 decimal string that rounds to the given binary floating-point value
191 and return either a pointer to the end of the string (a null character)
192 in the buffer, if the buffer was long enough, or 0. Other forms of
193 conversion are easily done with the help of gdtoa(), such as %e or %f
194 style and conversions with direction of rounding specified (so that, if
196 On IEEE-arithmetic systems that provide the C99 fegetround() function,
197 if compiled with -DHonor_FLT_ROUNDS, these routines honor the current
200 For an example of more general conversions based on dtoa(), see
203 For double-double -> decimal, g_ddfmt() assumes IEEE-like arithmetic
204 of precision max(126, #bits(input)) bits, where #bits(input) is the
205 number of mantissa bits needed to represent the sum of the two double
212 names end in _D2A. To make a "system" library, one could modify
218 Systems with preemptive scheduling of multiple threads require some
223 (The second lock, accessed in pow5mult, ensures lazy evaluation of
224 only one copy of high powers of 5; omitting this lock would introduce
225 a small probability of wasting memory, but would otherwise be harmless.)
231 By default, there is a private pool of memory of length 2000 bytes
234 is called only under very unusual circumstances (decimal -> binary
235 conversion of very long strings) for conversions to and from double
239 For extended and quad precisions, -DPRIVATE_MEM=20000 is probably
240 plenty even for many digits at the ends of the exponent range.
241 Use of the private pool avoids some overhead.
247 V. Paxson and W. Kahan, "A Program for Testing IEEE Binary-Decimal
248 Conversion", manuscript, May 1991,
249 ftp://ftp.ee.lbl.gov/testbase-report.ps.Z .
253 Some system-dependent additions to CFLAGS in the makefile:
255 HU-UX: -Aa -Ae
256 OSF (DEC Unix): -ieee_with_no_inexact
257 SunOS 4.1x: -DKR_headers -DBad_float_h
296 present conversion routines; for now, this README file must suffice.
297 Meanwhile, if you wish to write helper functions for other kinds of
298 IEEE-like arithmetic, some explanation of struct FPI and the bits
300 described by FPI *fpi. The bits array is of type ULong, a 32-bit
301 unsigned integer type. Floating-point numbers have fpi->nbits bits,
304 2^e (i.e., 2 to the power of the exponent e), where e is the second
306 and maximum exponent values fpi->emin and fpi->emax for normalized
307 floating-point numbers reflect this arrangement. For example, the
309 53 bits, with normalized values of the form 1.xxxxx... times 2^(b-1023),
315 exponent e = (b-1023) by 52:
317 fpi->emin = 1 - 1023 - 52
318 fpi->emax = 1046 - 1023 - 52
320 In various wrappers for IEEE double, we actually write -53 + 1 rather
321 than -52, to emphasize that there are 53 bits including one implicit bit.
322 Field fpi->rounding indicates the desired rounding direction, with
325 FPI_Round_near = unbiased rounding -- the IEEE default,
327 FPI_Round_down = toward -Infinity
330 Field fpi->sudden_underflow indicates whether strtodg should return
331 denormals or flush them to zero. Normal floating-point numbers have
332 bit fpi->nbits in the bits array on. Denormals have it off, with
333 exponent = fpi->emin. Strtodg provides distinct return values for normals
336 Compiling g__fmt.c, strtod.c, and strtodg.c with -DUSE_LOCALE causes
337 the decimal-point character to be taken from the current locale; otherwise
345 (Linux) systems -- not reflecting calls on fesetround(), as the C99
346 standard says it should -- when Honor_FLT_ROUNDS is #defined, the
350 Compile with -DUSE_LOCALE to use the current locale; otherwise
351 decimal points are assumed to be '.'. With -DUSE_LOCALE, unless
352 you also compile with -DNO_LOCALE_CACHE, the details about the
356 On machines with a 64-bit long double and perhaps a 113-bit "quad"
358 as Fprintf) to gdtoa.a. These are analogs, declared in stdio1.h, of