[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: integer exponentiation with negative exponent
- From: Coda Highland <chighland@...>
- Date: Fri, 11 Apr 2014 22:02:39 -0700
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:
>>> x = 2**56
>>> y = x + 1
>>> x
72057594037927936
>>> y
72057594037927937
>>> x == y
False
5.3work SHOULD give exactly the same results.
/s/ Adam