bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GAWK 5.1.0 doesn't work with 64bit numbers


From: Nelson H. F. Beebe
Subject: Re: GAWK 5.1.0 doesn't work with 64bit numbers
Date: Sun, 21 Mar 2021 08:41:27 -0600

Peter Brooks <peter.h.m.brooks@gmail.com> asks

>> Is the 'hidden bit' you refer to an overflow bit, if not, what is its
>> function?

No, it is not an overflow bit; it is just a normal significand bit
that is 1 for normal numbers, and 0 for subnormal numbers.  Take a
look at

        http://www.math.utah.edu/~beebe/arith/arith.pdf

for an overview of computer arithmetic.

Use of a hidden bit in the IEEE 754 32-bit, 64-bit, and 128-bit (but
not the 80-bit) formats, and DEC PDP-11 and VAX 32-bit and 64-bit
formats, is just a way to avoid having to deal with unnormalized
numbers in hardware circuitry, and gain about 1/3 decimal digit of
precision.

Peter also asks:

>> Shouldn't awk give a range error if asked to convert a number out of range?

Because of the IEEE 754 64-bit floating-point representation, all
64-bit integer values are in range of an awk number, though only 53 of
their bits are representable.  Historically, almost all programming
languages have accepted input numbers that nominally require more
precision than is available in storage:  thus, C code

        float pi_approx;
        piapprox = 3.141592653589793238462643383279503

does not raise any compiler warning, even though the variable has only
24 bits of precision.

This issue is further complicated by the practice of accepting decimal
input representations, but storing them in binary representations:
there is a base conversion issue that is well-understood by numerical
analysts, but not by most programmers, or the general public.

-------------------------------------------------------------------------------
- Nelson H. F. Beebe                    Tel: +1 801 581 5254                  -
- University of Utah                    FAX: +1 801 581 4148                  -
- Department of Mathematics, 110 LCB    Internet e-mail: beebe@math.utah.edu  -
- 155 S 1400 E RM 233                       beebe@acm.org  beebe@computer.org -
- Salt Lake City, UT 84112-0090, USA    URL: http://www.math.utah.edu/~beebe/ -
-------------------------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]