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

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

Issue 411263004: Implement trigonometric functions using a fdlibm port. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comment Created 6 years, 5 months 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
Index: test/mjsunit/sin-cos.js
diff --git a/test/mjsunit/sin-cos.js b/test/mjsunit/sin-cos.js
index 02ae57ba2773529d20e683eb63fc7b10d135bd26..4af7e6c9ccea8e5f8ab394e529fb5e4ad8bf74d7 100644
--- a/test/mjsunit/sin-cos.js
+++ b/test/mjsunit/sin-cos.js
@@ -157,8 +157,8 @@ assertEquals(0, Math.sin("0x00000"));
assertEquals(1, Math.cos("0x00000"));
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)));
+assertTrue(Math.tan(Math.PI/2) > 1e16);
+assertTrue(Math.tan(-Math.PI/2) < -1e16);
assertEquals("-Infinity", String(1/Math.sin("-0")));
// Assert that the remainder after division by pi is reasonably precise.
@@ -185,3 +185,71 @@ for (var i = -1024; i < 1024; i++) {
assertFalse(isNaN(Math.cos(1.57079632679489700)));
assertFalse(isNaN(Math.cos(-1e-100)));
assertFalse(isNaN(Math.cos(-1e-323)));
+
+// Tests for specific values expected from the fdlibm implementation.
+
+var two_32 = Math.pow(2, -32);
+var two_28 = Math.pow(2, -28);
+
+// Tests for Math.sin for |x| < pi/4
Raymond Toy 2014/07/24 16:51:12 I think you should add more comments on what these
Raymond Toy 2014/07/24 22:41:50 The spec also lists specific values for various ar
+assertEquals(Infinity, 1/Math.sin(+0.0));
+assertEquals(-Infinity, 1/Math.sin(-0.0));
+assertEquals(two_32, Math.sin(two_32));
Raymond Toy 2014/07/24 16:51:12 The two_32 and two_28 tests are to verify that sin
Yang 2014/07/28 11:29:00 Done.
+assertEquals(-two_32, Math.sin(-two_32));
+assertEquals(0.3826834323650898, Math.sin(Math.PI/8));
+assertEquals(-0.3826834323650898, -Math.sin(Math.PI/8));
Raymond Toy 2014/07/24 16:51:12 I think these 2 tests are intended to test case of
Yang 2014/07/28 11:29:00 Done.
+
+// Tests for Math.cos for |x| < pi/4
+assertEquals(1, Math.cos(two_32));
+assertEquals(1, Math.cos(-two_32));
Raymond Toy 2014/07/24 16:51:12 These two are for verifying cos(x) = 1 exactly for
Yang 2014/07/28 11:29:00 Done.
+assertEquals(0.9876883405951378, Math.cos(Math.PI/20));
+assertEquals(0.7100335477927638, Math.cos(0.7812504768371582));
+assertEquals(0.7100338835660797, Math.cos(0.78125));
+assertEquals(0.9238795325112867, Math.cos(Math.PI/8));
+assertEquals(0.9238795325112867, Math.cos(-Math.PI/8));
+
+// Tests for Math.tan for |x| < pi/4
+assertEquals("Infinity", String(1/Math.tan(0.0)));
+assertEquals("-Infinity", String(1/Math.tan(-0.0)));
+assertEquals(two_32, Math.tan(two_32));
+assertEquals(-two_32, Math.tan(-two_32));
+assertEquals(0.8211418015898941, Math.tan(11/16));
+assertEquals(-0.8211418015898941, Math.tan(-11/16));
+assertEquals(0.41421356237309503, Math.tan(Math.PI / 8));
+
+// Tests for Math.sin.
+assertEquals(0.479425538604203, Math.sin(0.5));
+assertEquals(-0.479425538604203, Math.sin(-0.5));
+assertEquals(1, Math.sin(Math.PI/2));
+assertEquals(-1, Math.sin(-Math.PI/2));
+assertEquals(1.2246467991473532e-16, Math.sin(Math.PI));
+assertEquals(-7.047032979958965e-14, Math.sin(2200*Math.PI));
+assertEquals(-0.7071067811865477, Math.sin(7/4 * Math.PI));
+assertEquals(0.7071067811865474, Math.sin(9/4 * Math.PI));
+assertEquals(0.7071067811865483, Math.sin(11/4 * Math.PI));
+assertEquals(-0.7071067811865479, Math.sin(13/4 * Math.PI));
+assertEquals(-3.2103381051568376e-11, Math.sin(1048576/4 * Math.PI));
+
+// Tests for Math.cos.
+assertEquals(1, Math.cos(two_28));
+assertEquals(0.9689124217106447, Math.cos(0.25));
+assertEquals(0.8775825618903728, Math.cos(0.5));
+assertEquals(0.7073882691671998, Math.cos(0.785));
+assertEquals(6.123233995736766e-17, Math.cos(Math.PI/2));
+assertEquals(0.7071067811865474, Math.cos(7/4 * Math.PI));
+assertEquals(0.7071067811865477, Math.cos(9/4 * Math.PI));
+assertEquals(-0.7071067811865467, Math.cos(11/4 * Math.PI));
+assertEquals(-0.7071067811865471, Math.cos(13/4 * Math.PI));
+assertEquals(0.9367521275331447, Math.cos(1000000));
+assertEquals(-3.435757038074824e-12, Math.cos(1048575/2 * Math.PI));
+
+// Tests for Math.tan.
+assertEquals(two_28, Math.tan(two_28));
+assertEquals(1.633123935319537e16, Math.tan(Math.PI/2));
+assertEquals(0.5463024898437905, Math.tan(0.5));
+assertEquals(0.8211418015898941, Math.tan(11/16));
+assertEquals(2.0000000000000027, Math.tan(1.107148717794091));
+assertEquals(-1.0000000000000004, Math.tan(7/4*Math.PI));
+assertEquals(0.9999999999999994, Math.tan(9/4*Math.PI));
+assertEquals(-6.420676210313675e-11, Math.tan(1048576/2*Math.PI));
+assertEquals(2.910566692924059e11, Math.tan(1048575/2*Math.PI));
Raymond Toy 2014/07/24 16:51:12 Now that the full Payne-Hanek reduction is impleme
Yang 2014/07/28 11:29:00 Done.

Powered by Google App Engine
This is Rietveld 408576698