lua-users home
lua-l archive

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


> 	Since 2.7 "has no integer representation", I could think that
> '2' also hasn't.  But that is not what happens:
> 
> Lua 5.3.0  Copyright (C) 1994-2014 Lua.org, PUC-Rio
> >return string.format("%d", '2.7')
> stdin:1: bad argument #2 to 'format' (number has no integer representation)
> stack traceback:
> 	[C]: in function 'string.format'
> 	stdin:1: in main chunk
> 	[C]: in ?
> >return string.format("%d", '2')
> 2
> >return string.format("%d", '2.0')
> 2
> 
> 	What is the rationale?	Are you considering a change on automatic
> coercion?  It will probably produce a great compatibility problem but
> it may be worth it...

The main difference here is that, unlike the coercion from floats to
integers---which was always undefined and, as my quiz shows, nobody
really knows how it works---the coercion from strings to numbers has
always been well defined and mostly everybody knows how it works.

-- Roberto