lua-users home
lua-l archive

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


On 13 April 2014 20:04, 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


I actually really like the idea.

The numerator is not always 1.
e.g. 10^-4 == 10//4 == 2