lua-users home
lua-l archive

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


Am 29.04.2014 10:09 schröbte Dirk Laurie:
2014-04-29 3:39 GMT+02:00 Tim Hill <drtimhill@gmail.com>:

On Apr 28, 2014, at 7:14 AM, Leo Razoumov <slonik.az@gmail.com> wrote:



As others pointed out already, integer exponentiation with full 64 bits
is useful (not to mention that it is usually faster, too). To make 2^3
an integer and 2^-3 a float breaks that guideline. But maybe that case
is worth the break.

I think that the "principle of least surprise" would favor 2^-3 == 0.125

--Leo--


I think the principle of least surprise here is consistency. I’m with Roberto on this one, in that it should only be the types that affect the outcome. If you really wanted to be consistent, you would have ^ that coerced both values to float and ^^ that coerced both (or one??) to integer, mirroring the new model for division. This would also, interestingly, not break existing 5.2 code.

It is your right to value consistency above usefulness — but not to claim
Roberto's support in doing so. Read that quote of his again. Roberto has
left the question open. "But maybe".

I think it's not about consistency above usefulness -- you can obviously have both: let ^ always return a floating point number and provide an extra `math.ipow` function for integer exponentiation. No consistency broken and all usefulness available -- but now you have a function call for integer exponentiation, so I don't know about the "usually faster" anymore ... `math.sqrt` doesn't return an integer for arguments like 4, 9, 16, etc., either, and the silent wrap-around for exponentiation of integers could be a gotcha as well, so better make it explicit (according to the above mentioned "principle of least surprise").

Philipp