lua-users home
lua-l archive

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



On 17/01/15 04:49 PM, Luiz Henrique de Figueiredo wrote:
How do I check if x can be represented as a float? For example, for
64-bit integers and 64-bit floats, (1<<62)+5 cannot be represented
as a float, but 1<<62 can.
print(x == math.tointeger(x+0.0))

What if x is a float?
print(x == (x+0.0))

If you need to distinguish integers from float, you can use math.type(x).

But please share why you need all this.

To check types? I guess that because Lua converts int to float without caring about precision loss (¬_¬) I don't need this, so meh... (only noticed now)

--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.