Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(882)

Unified Diff: test/mjsunit/sin-cos.js

Issue 66703005: Increase precision when finding the remainder after division by pi/2. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/runtime.cc ('K') | « src/runtime.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« src/runtime.cc ('K') | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698