[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: integer exponentiation with negative exponent
- From: "Alexandre (gaumerie)" <gaumerie@...>
- Date: Mon, 14 Apr 2014 13:00:07 +0100
>From my point of view, the most logical result would be to give 0 as a result. I think the result should be kept an integer, but we don't have an error for 1//2, so I am not expecting an error for 2^-1, but the same result for both.
Alexandre
--- Original Message ---
From: "Tim Hill" <drtimhill@gmail.com>
Sent: 14 April 2014 08:29
To: "Lua mailing list" <lua-l@lists.lua.org>
Subject: Re: integer exponentiation with negative exponent
On Apr 13, 2014, at 6:07 PM, Tim Hill <drtimhill@gmail.com> wrote:
>
> On Apr 13, 2014, at 5:04 PM, Coda Highland <chighland@gmail.com> wrote:
>
>> On Sun, Apr 13, 2014 at 3:25 PM, Tim Hill <drtimhill@gmail.com> wrote:
>>>
>>> If you assume the usual mathematical identity: x^-n == 1 / (x^n), is there any reason why 2^-3 cannot be treated as 1 // (2^3) ? This keeps the “type only” rule for how the operator is interpreted (which i agree with 100%). it also avoids surprises since, like other binary operators, if both values are integers you get an integer result (with the exception of division).
>>>
>>> —Tim
>>
>> You COULD, but it actually wouldn't make any difference. Treating it
>> as 1 // (x^n) would result in always returning 0 anyway except when
>> x==0 (returning NaN), x==1 (returning 1 for all n), or x ~= 0 && n==0
>> (returning 1 for all x).
>>
>> Now, if you change that definition to be / instead of //, thus
>> implying that it returns float instead of int, then that's perfectly
>> reasonable in my book.
>>
>> /s/ Adam
>>
>
> lol … you can tell i was tired when i wrote that can’t you?
>
> —Tim
>
Joking at my stupidity aside .. (hush) .. it really comes down to two choices:
1 / (x^(-n) … invert the sign and do floating point division
-or-
error
As Roberto said, work1 did the former, work2 the latter. Either is a special case in a certain sense. It’s just picking the latter of two evils.
—Tim