lua-users home
lua-l archive

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

Re What printf does with nan (0/0)
Sean Conner got a number when printing 0/0 but I get this behavior (in 5.2):

> x = 0/0
> print(string.format("one %d two",x))
stdin:1: bad argument #2 to 'format' (not a number in proper range)
stack traceback:
	[C]: in function 'format'
	stdin:1: in main chunk
	[C]: in ?
> print(string.format("one %f two",x))
one nan two

The "not in proper range" is the same error string.format gives for a large int.

On Jul 6, 2013, at 5:09 PM, Sean Conner <> wrote:

> It was thus said that the Great Jose Torre-Bueno once stated:
>> On Jul 6, 2013, at 9:37 AM, Tim Hill <> wrote:  this
>> entire model is to my mind elegant, cunning, and minimalist (all good
>> qualities).
>> I agree that the elegance is not to be lightly discarded.  In this
>> discussion I am not understanding what is wrong with using nan as a place
>> holder to make a table have array like properties.  To my mind another
>> advantage of nan is that string.format will not choke on it the way it
>> does on nil.
>  It does not, but what it does print is unexpected:
> [spc]lucy:~/source/6809/simp>lua
> Lua 5.1.5  Copyright (C) 1994-2012, PUC-Rio
>> x = 0/0
>> print(x)
> nan
>> print(string.format("one %d two",x))
> one -2147483648 two
>  -spc (Honestly did not expect that)