Index: test/mjsunit/sin-cos.js |
diff --git a/test/mjsunit/sin-cos.js b/test/mjsunit/sin-cos.js |
index 1176b6c9dab045d4435cacad34d7a58f7de24f5f..f45821a8f1740e3cd8e4eac091a86beb75ee1527 100644 |
--- a/test/mjsunit/sin-cos.js |
+++ b/test/mjsunit/sin-cos.js |
@@ -27,6 +27,8 @@ |
// Test Math.sin and Math.cos. |
+// Flags: --allow-natives-syntax |
+ |
function sinTest() { |
assertEquals(0, Math.sin(0)); |
assertEquals(1, Math.sin(Math.PI / 2)); |
@@ -141,3 +143,32 @@ assertTrue(isNaN(Math.sin(Infinity))); |
assertTrue(isNaN(Math.cos("-Infinity"))); |
assertEquals("Infinity", String(Math.tan(Math.PI/2))); |
assertEquals("-Infinity", String(Math.tan(-Math.PI/2))); |
+ |
+// Assert that the remainder after division by pi is reasonably precise. |
+function assertError(expected, x, epsilon) { |
Sven Panne
2013/11/20 07:38:35
Can we move this to mjsunit.js under a better name
|
+ assertTrue(Math.abs(x - expected) < epsilon); |
+} |
+ |
+assertError(0.9367521275331447, Math.cos(1e06), 1E-14); |
+assertError(0.8731196226768560, Math.cos(1e10), 1E-04); |
+assertError(0.9367521275331447, Math.cos(-1e06), 1E-14); |
+assertError(0.8731196226768560, Math.cos(-1e10), 1E-04); |
+assertError(-0.3499935021712929, Math.sin(1e06), 1E-14); |
+assertError(-0.4875060250875106, Math.sin(1e10), 1E-04); |
+assertError(0.3499935021712929, Math.sin(-1e06), 1E-14); |
+assertError(0.4875060250875106, Math.sin(-1e10), 1E-04); |
+ |
+// Assert that remainder calculation terminates even for large numbers |
+Math.sin(1e40); |
+Math.cos(1e50); |
+ |
+ |
+function no_deopt_on_minus_zero(x) { |
+ return Math.sin(x) + Math.cos(x) + Math.tan(x); |
+} |
+ |
+no_deopt_on_minus_zero(1); |
+no_deopt_on_minus_zero(1); |
+%OptimizeFunctionOnNextCall(no_deopt_on_minus_zero); |
+no_deopt_on_minus_zero(-0); |
+assertOptimized(no_deopt_on_minus_zero); |