gnu.utils.bug
[Top] [All Lists]
Try out TrashMail.net disposable email address service

Re: Bug with numeric calculation

Subject: Re: Bug with numeric calculation
From: John Cowan
Date: Thu, 17 Aug 2006 14:51:49 -0400
Newsgroups: gnu.utils.bug
Dr. C. Griewatsch scripsit:

> echo 1.0 1.1 | gawk '{print 0.1+$1-$2}'
> 0
> 
> echo 1.1 1.2 | gawk '{print 0.1+$1-$2}'
> 2.22045e-16
> 
> The same error can be reproduced with gawk 3.1.5 on the same machine,
> or with gawk 3.1.0 on Solaris 5.8, and with gawk 3.1.4 on Suse 9.3.

This is not a gawk bug, but a consequence of the fact that 0.1 does
not have an exact representation using IEEE floating-point numbers.
If you want exact decimal fraction arithmetic, use bc or dc or
Common Lisp or Scheme.

-- 
Here lies the Christian,                        John Cowan
        judge, and poet Peter,                  http://www.ccil.org/~cowan
Who broke the laws of God                       cowan@xxxxxxxx
        and man and metre.



<Prev in Thread] Current Thread [Next in Thread>