[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug with numeric calculation
From: |
John Cowan |
Subject: |
Re: Bug with numeric calculation |
Date: |
Thu, 17 Aug 2006 14:51:49 -0400 |
User-agent: |
Mutt/1.3.28i |
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 address@hidden
and man and metre.