[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Floating point
- From: "Joseph Manning" <manning@...>
- Date: Thu, 29 Oct 2015 17:29:09 +0000
On 2015-Oct-29 (Thu) at 17:16 (+0000), iain morland wrote:
>> If I assign a variable to the result of 23.2/0.2, and print that variable,
>> Lua outputs 116.
>>
>> However if I then use the same variable as the limit in an iterator,
>> the iterator stops on the 115th repeat, rather than the 116th as expected.
>>
>> So it therefore seems that the variable is a floating point number
>> between 115 and 116.
>>
>> I don't understand why I can't print the floating point value of this
>> variable. I haven't rounded or truncated it, so why does it print
>> exactly 116, even though that's not its value?
Iain,
$ lua53
Lua 5.3.1 Copyright (C) 1994-2015 Lua.org, PUC-Rio
> string.format( "%17.13f", 23.2/0.2 )
116.0000000000000
> string.format( "%18.14f", 23.2/0.2 )
115.99999999999999
Joseph
------------------------------------------------------------------------
Joseph Manning / Computer Science / UCC Cork Ireland / manning@cs.ucc.ie
------------------------------------------------------------------------