bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] gawk bug ?


From: Andrew J. Schorr
Subject: Re: [bug-gawk] gawk bug ?
Date: Fri, 3 Jul 2015 09:49:23 -0400
User-agent: Mutt/1.5.23 (2014-03-12)

Hi,

On Fri, Jul 03, 2015 at 11:20:15AM +0800, 袁亮 wrote:
> # chapter 2
> address@hidden ~]# cat 1
> 29.57
> 74.01
> address@hidden ~]# cat 2
> 103.58
> address@hidden ~]# 
> address@hidden ~]# awk 'NR==FNR{a+=$1;next}{b+=$1} END {if (a!=b) print a, b, 
> "bug"}' 1 2
> 103.58 103.58 bug
> address@hidden ~]# awk 'NR==FNR{a+=$1;next}{b+=$1} END {if (a!=b "") print a, 
> b, "bug"}' 1 2

Here's a more educational version of your test:

bash-4.2$ awk 'NR==FNR{a+=$1;next}{b+=$1} END {printf "%.15g\n", a-b}' 1 2
1.4210854715202e-14

Thus, this is an IEEE 754 numeric precision issue.  Please read the
documentation:
https://www.gnu.org/software/gawk/manual/html_node/Arbitrary-Precision-Arithmetic.html

And in particular:
https://www.gnu.org/software/gawk/manual/html_node/Inexact-representation.html#Inexact-representation

Regards,
Andy



reply via email to

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