[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Strange add results
- From: Drake Wilson <drake@...>
- Date: Sat, 20 Nov 2010 06:46:00 -0700
Quoth Alexey Malyshev <malma@kaluga.net>, on 2010-11-20 16:34:37 +0300:
> What's wrong with this code?
Nothing's "wrong" with it except that floating-point arithmetic isn't
doing what you expect but rather what it naturally does.
string.format('%.16f', 1+0.2+0.2+0.2+0.2+0.2)
==> "1.9999999999999998"
Go look on the Web regarding how binary fixed-precision floating-point
arithmetic often trips up people who are used to decimal arithmetic.
---> Drake Wilson