feat: add ceil, cos, sin, sqrt, isNan native methods and division-by-zero tests

Implement five new Num methods (ceil, cos, sin, sqrt, isNan) in wren_core.c and register them on the Num class. Add corresponding test files for ceil, floor, is_nan, and sqrt. Extend divide.wren with division-by-zero edge cases (inf, -inf, nan). Remove stale TODO comments from minus, multiply, and plus tests.
This commit is contained in:
Bob Nystrom
2014-01-08 15:47:14 +00:00
parent 693ab1c340
commit 193e4e30ab
9 changed files with 72 additions and 10 deletions
+8
View File
@@ -0,0 +1,8 @@
IO.print(123.ceil) // expect: 123
IO.print(-123.ceil) // expect: -123
IO.print(0.ceil) // expect: 0
IO.print(-0.ceil) // expect: -0
IO.print(0.123.ceil) // expect: 1
IO.print(12.3.ceil) // expect: 13
IO.print(-0.123.ceil) // expect: -0
IO.print(-12.3.ceil) // expect: -12
+11 -4
View File
@@ -1,5 +1,12 @@
IO.print(8 / 2) // expect: 4
IO.print(12.34 / -0.4) // expect: -30.85
IO.print(8 / 2) // expect: 4
IO.print(12.34 / -0.4) // expect: -30.85
// TODO: Unsupported RHS types.
// TODO: Divide by zero.
// Divide by zero.
IO.print(3 / 0) // expect: inf
IO.print(-3 / 0) // expect: -inf
IO.print(0 / 0) // expect: nan
IO.print(-0 / 0) // expect: nan
IO.print(3 / -0) // expect: -inf
IO.print(-3 / -0) // expect: inf
IO.print(0 / -0) // expect: nan
IO.print(-0 / -0) // expect: nan
+8
View File
@@ -0,0 +1,8 @@
IO.print(123.floor) // expect: 123
IO.print(-123.floor) // expect: -123
IO.print(0.floor) // expect: 0
IO.print(-0.floor) // expect: -0
IO.print(0.123.floor) // expect: 0
IO.print(12.3.floor) // expect: 12
IO.print(-0.123.floor) // expect: -1
IO.print(-12.3.floor) // expect: -13
+5
View File
@@ -0,0 +1,5 @@
IO.print(1.isNan) // expect: false
IO.print((0/0).isNan) // expect: true
// Infinity is not NaN.
IO.print((1/0).isNan) // expect: false
-2
View File
@@ -6,5 +6,3 @@ IO.print(3 - 2 - 1) // expect: 0
// Unary negation.
var a = 3
IO.print(-a) // expect: -3
// TODO: Unsupported RHS types.
-2
View File
@@ -1,4 +1,2 @@
IO.print(5 * 3) // expect: 15
IO.print(12.34 * 0.3) // expect: 3.702
// TODO: Unsupported RHS types.
-2
View File
@@ -1,5 +1,3 @@
IO.print(1 + 2) // expect: 3
IO.print(12.34 + 0.13) // expect: 12.47
IO.print(3 + 5 + 2) // expect: 10
// TODO: Unsupported RHS types.
+10
View File
@@ -0,0 +1,10 @@
IO.print(4.sqrt) // expect: 2
IO.print(1000000.sqrt) // expect: 1000
IO.print(1.sqrt) // expect: 1
IO.print(-0.sqrt) // expect: -0
IO.print(0.sqrt) // expect: 0
IO.print(2.sqrt) // expect: 1.4142135623731
IO.print(-4.sqrt.isNan) // expect: true
// TODO: Tests for sin and cos.