Previous: , Up: Arbitrary-Precision Arithmetic Features in gawk   [Contents][Index]

16.3.2 Arbitrary Precision Introduction

By default, gawk uses the double-precision floating-point values supplied by the hardware of the system it runs on. However, if it was compiled to do so, and the -M command-line option is supplied, gawk uses the GNU MPFR and GNU MP (GMP) libraries for arbitrary-precision arithmetic on numbers. You can see if MPFR support is available like so:

$ gawk --version
-| GNU Awk 5.2.0, API 3.2, PMA Avon 7, (GNU MPFR 4.0.1, GNU MP 6.1.2)
-| Copyright (C) 1989, 1991-2022 Free Software Foundation.

(You may see different version numbers than what’s shown here. That’s OK; what’s important is to see that GNU MPFR and GNU MP are listed in the output.)

Additionally, there are a few elements available in the PROCINFO array to provide information about the MPFR and GMP libraries (see Built-in Variables That Convey Information).

The MPFR library provides precise control over precisions and rounding modes, and gives correctly rounded, reproducible, platform-independent results. With the -M command-line option, all floating-point arithmetic operators and numeric functions can yield results to any desired precision level supported by MPFR.

Two predefined variables, PREC and ROUNDMODE, provide control over the working precision and the rounding mode. The precision and the rounding mode are set globally for every operation to follow. See Setting the Precision and Setting the Rounding Mode for more information.