feat(stdlib): implement math.fmod for bitwise.lua bit32 verification#199
Merged
Conversation
Adds `math.fmod(x, y)` per Lua 5.3 §6.7 — truncated-quotient remainder. Returns an integer when both args are integers, otherwise a float computed via :math.fmod/2. Integer zero divisor raises "bad argument #2 ... (zero)"; mininteger / -1 short-circuits to 0 to match the C implementation's overflow guard. Unblocks bitwise.lua's bit32.lshift verification block (line 278), so the file now passes end-to-end. Moved from @skipped_tests to @ready_tests. Plan: A5a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add math.fmod for bitwise.lua bit32 verification
Plan:
.agents/plans/A5a-bitwise-suite-math-fmod.mdGoal
Implement
math.fmodsobitwise.luacan finish its bit32-libraryverification block (line 278 onward). This was the last remaining gap
discovered while shipping A5.
Success criteria
math.fmod(x, y)works per Lua 5.3 §6.7: "Returns the remainderof the division of x by y that rounds the quotient towards zero."
Truncated-quotient remainder via
Kernel.rem/2for integers and:math.fmod/2for floats.math.fmodof two integers returns an integer; otherwise returnsa float. Verified by
math.fmod returns integer remainderandmath.fmod with mixed int/float returns a floattests.mix testpasses, no regressions. 1394 → 1402 tests, 0 failures(8 new tests, 1 fewer skipped —
bitwise.luamoved from@skipped_teststo@ready_tests).test/lua/vm/stdlib/math_test.exscoverinteger/integer, integer/float, float/float, negative dividend,
mininteger / -1overflow guard, integer divide-by-zero (raises"bad argument Add CI #2 ... (zero)"), float divide-by-zero (raises — see
Discoveries), non-number argument errors, and missing-argument
errors.
bitwise.luapasses end-to-end. Verified by running the filedirectly and by adding it to
@ready_tests(mix test --only lua53passes 5 ready files now).Changes
Discoveries
math.fmod(x, 0.0)when either argument is afloat. The BEAM has no NaN value, and the rest of this VM raises on
zero-divisor float arithmetic (see
safe_divideinlib/lua/vm/executor.ex:1690). For consistency we raisebad argument #2 to 'math.fmod' (zero)for both integer and float zero divisors.Documented inline in
lib/lua/vm/stdlib/math.ex.math.fmod(mininteger, -1)is short-circuited to0to avoidan overflow trap (matches the C implementation in
lmathlib.c'sspecial case for
d == -1).bitwise.luafrom@skipped_teststo@ready_testsintest/lua53_suite_test.exs, locking in the suite-count gain.math.*gaps surfaced while wiring fmod in.math.modfandmath.atan2are not exercised bybitwise.lua.Verification
Out of scope (intentional)
math.*functions (math.modf,math.atan2, etc.)unless also exercised by
bitwise.lua. None surfaced.package.searcherstable — separate concern from thepackage.preloadhook added in A5.