bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: it looks like bug:(


From: Micah Cowan
Subject: Re: it looks like bug:(
Date: Thu, 18 Oct 2007 09:28:27 -0700
User-agent: Thunderbird 1.5.0.13 (X11/20070824)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Александр Шкотин wrote:
> please try this
>
> BEGIN{
> w = 0.0
> w = w + 0.15
> w = w + 99.45
> w = w + 0.4
> if (w > 100)
>  print w
> }
>
> it prints 100
>
> with GNU Awk 3.1.3 under Win XP and GNU Awk 3.1.5 under Fedora.

By default, non-integer numbers are converted as if you had said:
printf("%.6g\n", w);

Try changing ‘print w’ to ‘printf("%.24g\n", w)’, or just set OFMT to a
value of "%.24g". OFMT is the conversion specification used to convert
numbers to strings for output; CONVFMT is used to convert numbers to
strings when required by an expression.

You'll see that the number is actually slightly greater than 100.
Floating-point numbers are not exact representations, and many numbers
cannot be represented exactly using floating-point.

- --
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHF4mr7M8hyUobTrERCDxxAJwPIorrVNJ5KlphEbqMKqHr/pzZlgCgglaT
uBJDIkjsOk+YyN53r/CmhSU=
=whb8
-----END PGP SIGNATURE-----





reply via email to

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