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:
Bob Nystrom
2013-11-10 05:01:18 +00:00
parent 98d6bbbcc1
commit c430056f70
4 changed files with 21 additions and 2 deletions
+1
View File
@@ -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.
+12
View File
@@ -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.