lua-users home
lua-l archive

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


On 4/29/14, Tim Hill <drtimhill@gmail.com> wrote:
>
> “I agree with the original rationale (as outlined by Roberto, with some
> reservations) that only the types of values affect the outcome, not the
> values”.
>

In math the type of a result of a numeric operation DOES depend on the values
of the operands because some arithmetic operations (notably division)
are not closed in integers.

For example, take division: 4/2 == 2: two integers go in and one
integer goes out and all the math properties of division
are preserved. On the other hand, 5/3 poses a problem. You either
perform a floating point division which  changes
the type, or preserve the type by doing an integer division which
breaks associativity of the division.
If you insist you can have full type consistency but then do not call
them the arithmetic operations.

By demanding type invariance one goes back to the arithmetic model of C
where you have to carefully track the numeric types.
Lua has a simple and consistent math based upon a single numeric type
-- 64-bit float.

--Leo--