lua-users home
lua-l archive

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


On Mon, Apr 28, 2014 at 9:39 PM, Tim Hill <drtimhill@gmail.com> wrote:

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.

—Tim



Let's keep in mind that Lua also coerces between string and number types automatically, e.g. with the concat operator and string.format. (And I consider this a very good thing, as it eliminates a lot of tostring() all over my code.) It'd be more surprising and less self-consistent if it *didn't* coerce between number and integer automatically.

--
Sent from my Game Boy.