lua-users home
lua-l archive

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


> >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.

We considered all those options:

* A separated operation (^^, like //) may be the most consistent, but it
seems an overkill. Unlike division, where the "usual" is a non-integer
result, exponentiation "typically" gives integer results for integer
operations (frequently people even forget about negative exponents).

* Returning 0 (plus all exception cases) seems consistent but useless
(and often unexpected).

* Returning a float is easier for compatibility and useful when you do
not care for the difference between float and int. It may or may not
be what one is expecting, as this discussion shows. (I guess that when
one writes x^-3, with a literal negative integer, she probably expects a
float; but when one writes n^m in an integer computation and m happens
to be negative, that may be a bug somewhere else in the code.)

* The error option has the advantage that it calls the programmer
attention to the fact that the operation might not be doing what she
intended, and so she has to be more explicit (e.g., ensuring that one of
the operands is a float).

-- Roberto