bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] How does awk implement extremely long integers?


From: arnold
Subject: Re: [bug-gawk] How does awk implement extremely long integers?
Date: Wed, 1 Feb 2012 09:27:42 -0800

Hi.

> Date: Wed, 1 Feb 2012 09:14:47 -0600
> From: John Haque <address@hidden>
> To: "Nelson H. F. Beebe" <address@hidden>
> Cc: address@hidden
> Subject: Re: [bug-gawk] How does awk implement extremely long integers?
>
> Hi.
>
> On Tue, Jan 31, 2012 at 10:53:30AM -0700, Nelson H. F. Beebe wrote:
>  
> > All gawk implementations (gawk, nawk, awk, mawk, tawk, jawk, ...) by
> > default use a numeric type implemented as a double, which on modern
> > systems is always the IEEE 754 64-bit format.  It has a 53-bit
> > significand, with a separate sign, so numbers in the range
> > [0, 2**53 - 1] can be represented exactly.
> > 
> > For the applications for which awk was intended, that is mostly adequate.
> > I have private versions of mawk and nawk that have been extended for
> > 80-bit and 128-bit long double IEEE 754 formats, and also for 128-bit
> > IEEE 754-2008 decimal arithmetic.  See
> > 
> >     http://www.math.utah.edu/pub/mathcw/
>
> I assume the modified gcc has additional format specifiers to print
> "long" integers?

I think so.

> The GNU mpfr library does not have any built-in facility
> to output "long" integers  what I tell after looking at the online
> doc.

Understanding how to support printf formats for MPFR is just one of the
challenges to adding support for it.

> BTW, if I am not mistaken, gawk used to print long integers as
> floating point numbers in the old days. Is this going to be an issue
> for gawk?
>
> $ gawk --version
> GNU Awk 3.1.5
>
> $ gawk 'BEGIN { print 1000*342413245}'
> 3.42413e+11

Yes, in the Olden Days, if a value was out of range for an integer,
gawk fell back to %g.  This was better than what other awks did, which
was to print MAX_INT.

At some point (undoubtedly it can be found in the ChangeLog), I moved
to using printf %.0f which prints values as full integers.  This follows
a more literal interpretation of the standard, which says that "print"
prints integral values as integers, without saying anything about ranges.

Arnold



reply via email to

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