feat(phase-4): Type-Safe Arithmetic & Comparisons #118
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type-Safe Arithmetic & Comparisons
Goal
Proper Lua 5.3 arithmetic semantics with clear error messages.
Implementation
Float Division by Zero: Updated to approximate Lua 5.3 behavior:
positive / 0returns1.0e308(approximating +inf)negative / 0returns-1.0e308(approximating -inf)0 / 0returns0.0(approximating NaN)Note: True IEEE 754 infinity/NaN are difficult to create in Elixir/Erlang due to strict arithmetic checks. This is a documented limitation.
Arithmetic Type Checking (already complete):
safe_*helpers with type checkingTypeErrorraised for non-numeric operands with clear messagesComparison Safety (already complete):
==and~=work on any types (return false for different types)<,<=,>,>=only work on numbers or strings (same type)TypeErrorraised for incompatible type comparisonsChanges
lib/lua/vm/executor.ex- Updatedsafe_divideto handle division by zerotest/lua/vm/arithmetic_test.exs- Updated division by zero testsVerification
mix formatcompletedmix compile --warnings-as-errorspassesmix test --exclude pendingpasses (1,011 tests)