lua-users home
lua-l archive

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


On 04/12/2014 09:34 AM, Rena wrote:
On Fri, Apr 11, 2014 at 9:29 PM, Doug Currie <doug.currie@gmail.com <mailto:doug.currie@gmail.com>> wrote:

        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.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio

    > =4^(-1)

    0.25

    -- e


So it works as expected in 5.2 but not in 5.3. Seems like a bug. Even if intended, I don't like it for the potential to break existing code for no good reason.

--
Sent from my Game Boy.

having looked at the `luaV_pow' in lvm.c, I found it is _intentionally_ reported as an error (at least
for current work version) -- since this function translates `pow' into a serial of `mult' operations.
But this `luaV_pow' is only called when both operands of the OP_POW are integers. for float point numbers,
`l_mathop(pow)' is used instead.
Lua 5.2 don't have two different internal number representations, thus the negative exponent is OK.


but, same as Rena, I don't like this behavior either;
one reason is the potential to break existing code, as Rena pointed.
another reason is that I think users should see as little differece between the number representations as possible,
ans the pow is not concerned as much as the div operator whether it is an integer or float point operaton.

is the gain (if any) of a special integer pow operation worth the semantic change?