Next: , Previous: , Up: Arbitrary Precision Arithmetic   [Contents][Index]

15.4 Arbitrary Precision Floating-point Arithmetic with gawk

gawk uses the GNU MPFR library for arbitrary precision floating-point arithmetic. The MPFR library provides precise control over precisions and rounding modes, and gives correctly rounded, reproducible, platform-independent results. With one of the command-line options --bignum or -M, all floating-point arithmetic operators and numeric functions can yield results to any desired precision level supported by MPFR. Two built-in variables, PREC and ROUNDMODE, provide control over the working precision and the rounding mode (see Setting Precision, and see Setting Rounding Mode). The precision and the rounding mode are set globally for every operation to follow.

The default working precision for arbitrary precision floating-point values is 53 bits, and the default value for ROUNDMODE is "N", which selects the IEEE-754 roundTiesToEven rounding mode (see Rounding Mode).94 gawk uses the default exponent range in MPFR (emax = 2^30 - 1, emin = -emax) for all floating-point contexts. There is no explicit mechanism to adjust the exponent range. MPFR does not implement subnormal numbers by default, and this behavior cannot be changed in gawk.

NOTE: When emulating an IEEE-754 format (see Setting Precision), gawk internally adjusts the exponent range to the value defined for the format and also performs computations needed for gradual underflow (subnormal numbers).

NOTE: MPFR numbers are variable-size entities, consuming only as much space as needed to store the significant digits. Since the performance using MPFR numbers pales in comparison to doing arithmetic using the underlying machine types, you should consider using only as much precision as needed by your program.



The default precision is 53 bits, since according to the MPFR documentation, the library should be able to exactly reproduce all computations with double-precision machine floating-point numbers (double type in C), except the default exponent range is much wider and subnormal numbers are not implemented.

Next: , Previous: , Up: Arbitrary Precision Arithmetic   [Contents][Index]