[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: integer exponentiation with negative exponent
- From: Roberto Ierusalimschy <roberto@...>
- Date: Sun, 13 Apr 2014 17:34:30 -0300
> (I already had to change existing Lua code to get it running with
> work2.) Wouldn't it be more logical, if exponentiation with negative
> exponent would convert the base argument to float, similar to the
> division case?
Lua 5.3 work 1 worked that way. We changed to follow a guideline that
the type of the result of an operation should not depend on the *values*
of the operands, only on their types. (Note that all other operators
satisfy this rule; the division, in particular, always convert its
arguments to floats.)
As others pointed out already, integer exponentiation with full 64 bits
is useful (not to mention that it is usually faster, too). To make 2^3
an integer and 2^-3 a float breaks that guideline. But maybe that case
is worth the break.
-- Roberto