lua-users home
lua-l archive

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


> I kinda-sorta get that, but if you follow your logic then I don’t
> really see them as “sub-types” but fully distinguished types.

I do not see why. What is the difference between these types? The value
is what is important, not the type. If you have a number with a value
of 1, it does not matter whether it is an integer or a float (in almost
all contexts). If you have a number with a value of 1.4, it also does
not matter whether it is an integer or a float :) We could have defined
the "integer" operations (integer division and bitwise operations) using
only old-style floats, with a specification that they would only work
on integral values within a given range. (Javascript does something
along these lines, but it truncate values [not types].)  In Lua 5.2,
lua_tointeger could refuse to convert numbers that were not exact
integers in C, again without having any new type in the language.

As Alexandre said, care must be taken to the operations to not get a
unexpected error. The logic for the current behavior is that, more often
than not, the alternative to an unexpected error would be an unexpected
result. (What is the "expected result" of 4.5//1.5 or -5.2|-1.3?)

-- Roberto