lua-users home
lua-l archive

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


On 04/12/2014 01:02 PM, Coda Highland wrote:
On Fri, Apr 11, 2014 at 9:05 PM, Peng Zhicheng
<pengzhicheng1986@gmail.com> wrote:
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?
Consider (this is Lua 5.1):

x = 2^56
y = x + 1
=x
7.2057594037928e+16
=y
7.2057594037928e+16
=x == y
true

The actual value is 72057594037927936. This is an exact number, with
no precision loss, but the float version gets it wrong.

Now, I don't have 5.3work installed, but I do have Python, which uses
integer exponentiation:



I can't agree.

double precision floating point number has 56 precision bits, while long long has 64.
there is not much difference.
if you need more than 56, double is not enough.
what if you need more than 64? long long is not enough either.

speaking of correctness,  that `x == x+1' is of course incorrect.
so is 'x ^ y == 0' where x is not zero.

I am personally concerned about overflow more than losing precision.