bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] awk integer math.


From: Aharon Robbins
Subject: Re: [bug-gawk] awk integer math.
Date: Tue, 16 Sep 2014 20:28:25 +0300
User-agent: Heirloom mailx 12.5 6/20/10

Hello. Thank you for your note.

> Date: Tue, 16 Sep 2014 03:48:12 -0400
> From: Mark Cross <address@hidden>
> To: address@hidden
> Subject: [bug-gawk] awk integer math.
>
> awk fails to correctly calculate 6^36 (or equivalent 6**36).
>
> execute                          -->  gawk 'BEGIN{print 6^36}'
> get                                 -->  10314424798490536576964100096
> code for expected value   -->  export BC_LINE_LENGTH=0; echo "6^36"| bc -l
> expected correct value     -->  10314424798490535546171949056
> diff                                  -->  00000000000000001030792151040
>
> Using this version: gawk -V     GNU Awk 4.0.1

Gawk uses hardware double precision floating point values for all
mathematical operations. This is clearly documented; the values you
are trying to compute are outside the range of a C double.

I am curious why you are expecting gawk to be able to do infinite
precision arithmetic like bc / dc?  This seems to be a common misconception.

With gawk 4.1.0 and later, as Andy pointed out, if gawk was built to
use the MPFR and GMP libraries, you can do arbitrary precision floating
point operations with the -M option and by setting the precision to be
large enough with the PREC variable.

But the version you have doesn't support that - you may wish to upgrade.
The latest version is 4.1.1.

Hope this helps,

Arnold



reply via email to

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