lua-users home
lua-l archive

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


On 04/12/2014 11:01 AM, Coda Highland wrote:
On Fri, Apr 11, 2014 at 7:23 PM, Peng Zhicheng
<pengzhicheng1986@gmail.com> wrote:
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?
It's probably faster, but the problem can be addressed by also using
the floating-point version when the RHS operand is negative. It seems
a simple enough change to me.

/s/ Adam

It may be faster. but it is the semantic difference that I was concerned.
I suppose the pow function would quite usually overflow a integer(even 64-bit long),
do we really need a dedicated `pow' for integers?

---------8x---------------------------------------
Lua 5.3.0 (work2)  Copyright (C) 1994-2014 Lua.org, PUC-Rio
> 1000^30
0
> 1000^30.0
1e+90
>
---------8x----------------------------------------


and, actually I am not very confident about the performance, since it shifts bits
and multiply (by default 64-bit) integers; would that be faster than the FPU? how much faster?

but for this we must do some measurements.