lua-users home
lua-l archive

Re: Strange add results

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


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

AltStyle によって変換されたページ (->オリジナル) /