lua-users home
lua-l archive

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


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