gawk: Math Definitions

1 
1 15.2 Other Stuff to Know
1 ========================
1 
1 The rest of this major node uses a number of terms.  Here are some
1 informal definitions that should help you work your way through the
1 material here:
1 
1 "Accuracy"
1      A floating-point calculation's accuracy is how close it comes to
1      the real (paper and pencil) value.
1 
1 "Error"
1      The difference between what the result of a computation "should be"
1      and what it actually is.  It is best to minimize error as much as
1      possible.
1 
1 "Exponent"
1      The order of magnitude of a value; some number of bits in a
1      floating-point value store the exponent.
1 
1 "Inf"
1      A special value representing infinity.  Operations involving
1      another number and infinity produce infinity.
1 
1 "NaN"
1      "Not a number."(1)  A special value that results from attempting a
1      calculation that has no answer as a real number.  In such a case,
1      programs can either receive a floating-point exception, or get
1      'NaN' back as the result.  The IEEE 754 standard recommends that
1      systems return 'NaN'.  Some examples:
1 
1      'sqrt(-1)'
1           This makes sense in the range of complex numbers, but not in
1           the range of real numbers, so the result is 'NaN'.
1 
1      'log(-8)'
1           -8 is out of the domain of 'log()', so the result is 'NaN'.
1 
1 "Normalized"
1      How the significand (see later in this list) is usually stored.
1      The value is adjusted so that the first bit is one, and then that
1      leading one is assumed instead of physically stored.  This provides
1      one extra bit of precision.
1 
1 "Precision"
1      The number of bits used to represent a floating-point number.  The
1      more bits, the more digits you can represent.  Binary and decimal
1      precisions are related approximately, according to the formula:
1 
1           PREC = 3.322 * DPS
1 
1      Here, _prec_ denotes the binary precision (measured in bits) and
1      _dps_ (short for decimal places) is the decimal digits.
1 
1 "Rounding mode"
1      How numbers are rounded up or down when necessary.  More details
1      are provided later.
1 
1 "Significand"
1      A floating-point value consists of the significand multiplied by 10
1      to the power of the exponent.  For example, in '1.2345e67', the
1      significand is '1.2345'.
1 
1 "Stability"
1      From the Wikipedia article on numerical stability
1      (https://en.wikipedia.org/wiki/Numerical_stability): "Calculations
1      that can be proven not to magnify approximation errors are called
1      "numerically stable"."
1 
1    See the Wikipedia article on accuracy and precision
1 (https://en.wikipedia.org/wiki/Accuracy_and_precision) for more
1 information on some of those terms.
1 
1    On modern systems, floating-point hardware uses the representation
1 and operations defined by the IEEE 754 standard.  Three of the standard
1 IEEE 754 types are 32-bit single precision, 64-bit double precision, and
1 128-bit quadruple precision.  The standard also specifies extended
1 precision formats to allow greater precisions and larger exponent
1 ranges.  ('awk' uses only the 64-bit double-precision format.)
1 
1    ⇒Table 15.3 table-ieee-formats. lists the precision and
1 exponent field values for the basic IEEE 754 binary formats.
1 
1 Name           Total bits     Precision      Minimum        Maximum
1                                              exponent       exponent
1 ---------------------------------------------------------------------------
1 Single         32             24             -126           +127
1 Double         64             53             -1022          +1023
1 Quadruple      128            113            -16382         +16383
1 
1 Table 15.3: Basic IEEE format values
1 
1      NOTE: The precision numbers include the implied leading one that
1      gives them one extra bit of significand.
1 
1    ---------- Footnotes ----------
1 
1    (1) Thanks to Michael Brennan for this description, which we have
1 paraphrased, and for the examples.
1