feat: implement modulo operator for numbers with fmod and add test suite
Add num_mod primitive using fmod from math.h to support the % operator on number types. Register the new primitive in the numClass method table. Include a comprehensive test file covering positive, negative, and left-associative modulo cases, plus a divide-by-zero TODO comment in the existing division test.
This commit is contained in:
@@ -2,3 +2,4 @@ io.write(8 / 2) // expect: 4
|
||||
|
||||
// TODO(bob): Floating point numbers.
|
||||
// TODO(bob): Unsupported RHS types.
|
||||
// TODO(bob): Divide by zero.
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
io.write(5 % 3) // expect: 2
|
||||
io.write(10 % 5) // expect: 0
|
||||
io.write(-4 % 3) // expect: -1
|
||||
io.write(4 % -3) // expect: 1
|
||||
io.write(-4 % -3) // expect: -1
|
||||
|
||||
// Left associative.
|
||||
io.write(13 % 7 % 4) // expect: 2
|
||||
|
||||
// TODO(bob): Floating point numbers.
|
||||
// TODO(bob): Unsupported RHS types.
|
||||
// TODO(bob): Error on mod by zero.
|
||||
Reference in New Issue
Block a user