[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: print("0"+1)
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 25 Mar 2015 12:44:00 -0300
> First, here are some bits from the manual:
>
> Coercions and Conversions http://www.lua.org/manual/5.3/manual.html#3.4.3
> [...], the string is converted to an integer or a float, following its
> syntax and the rules of the Lua lexer.
Read the rest of that paragraph:
Then, the resulting number is converted to the required type (float or
integer) according to the previous rules.
So, you have to know what is "the required type". In the case of addition,
see 3.4.1 – Arithmetic Operators:
With the exception of exponentiation and float division, the
arithmetic operators work as follows: If both operands are integers,
the operation is performed over integers and the result is an
integer. Otherwise, if both operands are numbers or strings that
can be converted to numbers (see §3.4.3), then they are converted
to floats, the operation is performed following the usual rules for
floating-point arithmetic (usually the IEEE 754 standard), and the
result is a float.
That is, "the required type" is float in that case.
-- Roberto