lua-users home
lua-l archive

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




On 17/01/2015 09:29, Alexandre (gaumerie) wrote:
I was not expecting that behaviour neither. However, it is consistent with what Roberto told during the conversation about the power (x^y) operator: the result type of the operator should depends only on the operandes types and not the operandes values.
If string where converted to integer or float according their values in the addition operation, you would have:
   String + Integer -> Integer (if the string represents an integer) or Float (if the string represents a float)
The current behaviour give:
   String + Integer -> Float
   String + Float -> Float
in all cases (given that the string represents a valid number) and so there is no surprise about the result type.


Ah! Yes! This makes sense. I didn't got that point. This is indeed a very sensible choice. Maybe it would be nice to stress this thing in the manual. As It was shown to me in another post, the manual is precise about that, but I think it is not straightforward.

   Alexandre

--- Original Message ---

From: "Dirk Laurie" <dirk.laurie@gmail.com>
Sent: 17 January 2015 07:20
To: "Lua mailing list" <lua-l@lists.lua.org>
Subject: Re: Lua 5.3: wrong coercion?

2015-01-17 0:29 GMT+02:00 Lorenzo Donati <lorenzodonatibz@tiscali.it>:

the whole string->number automatic coercion thing seems to have become a bit
overcomplicated.

It's the same as it always was, but we've started talking
about it a lot more. At the C code level it just does the
minimum, as Roberto explained.