lua-users home
lua-l archive

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


> On Jan 17, 2015, at 12:29 AM, Alexandre (gaumerie) <gaumerie@hotmail.com> 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.
> 

For me, the “surprise" is that implicit coercion of a string to an integer behaves differently to explicit coercion (via tonumber()). I’m not saying it’s not according to the spec, just that it’s a bit .. well .. surprising.

—Tim