Bug 897634 - Add more testcase for Math.expm1. r=jorendorff
authorTooru Fujisawa <arai_a@mac.com>
Mon, 04 Jul 2016 02:32:11 +0900
changeset 328535 ffc6d04b8cd7671554668656bee3ea7a5fd26ccd
parent 328534 eac0c056235ee1174fc092fe159d2d5710331fbd
child 328536 3c6a23adca89368b25f3ec252b236049f8779946
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs897634
milestone50.0a1
Bug 897634 - Add more testcase for Math.expm1. r=jorendorff
js/src/tests/ecma_6/Math/expm1-approx.js
js/src/tests/ecma_6/Math/expm1-monotonicity.js
--- a/js/src/tests/ecma_6/Math/expm1-approx.js
+++ b/js/src/tests/ecma_6/Math/expm1-approx.js
@@ -4,21 +4,59 @@ assertNear(Math.expm1(1e-14), 1.00000000
 assertNear(Math.expm1(1e-6), 0.0000010000005000001665);
 
 var expm1_data = [
     [ -1.875817529344e-70, -1.875817529344e-70 ],
     [ -7.09962844069878e-15, -7.099628440698755e-15 ],
     [ -2.114990849122478e-10, -2.1149908488988187e-10 ],
     [ -0.0000031404608812881633, -0.000003140455950046052 ],
 
+    [ -0.0000011039855962733358, -0.0000011039849868814618 ],
+    [ -0.000015114666893502755, -0.0000151145526675006 ],
+    [ -0.000033870281179478836, -0.000033869707587981166 ],
+    [ -0.00043952149320897676, -0.00043942491778698985 ],
+    [ -0.005553725496786973, -0.005538332073473123 ],
+    [ -0.05122020579778827, -0.049930563302241604 ],
+    [ -0.4721357117742938, -0.3763311320344197 ],
+    [ -1.2781607348262256, -0.7214508446489242 ],
+
     [ 1.875817529344e-70, 1.875817529344e-70 ],
     [ 6.261923313140869e-30, 6.261923313140869e-30 ],
     [ 7.09962844069878e-15, 7.099628440698805e-15 ],
     [ 1.3671879628418538e-12, 1.3671879628427884e-12 ],
     [ 2.114990849122478e-10, 2.1149908493461373e-10 ],
     [ 1.6900931765206906e-8, 1.6900931908027652e-8 ],
-    [ 0.0000031404608812881633, 0.0000031404658125405988 ]
+    [ 0.0000031404608812881633, 0.0000031404658125405988 ],
+
+    [ 0.0000011039855962733358, 0.0000011039862056656584 ],
+    [ 0.000015114666893502755, 0.000015114781120655907 ],
+    [ 0.000033870281179478836, 0.00003387085478392845 ],
+    [ 0.00043952149320897676, 0.0004396180969330924 ],
+    [ 0.005553725496786973, 0.005569176019645543 ],
+    [ 0.05122020579778827, 0.05255464640120383 ],
+    [ 0.4721357117742938, 0.6034149712523235 ],
+    [ 1.2781607348262256, 2.590030631181154 ],
+
+    [ 3.0693960800487883, 20.528897017773147 ],
+    [ 5.560441648750136, 258.9376120972927 ],
+    [ 7.4227656046482595, 1672.6557833191303 ],
+    [ 11.378926299184645, 87458.07941992789 ],
 ];
 
 for (var [x, y] of expm1_data)
     assertNear(Math.expm1(x), y);
 
+var sloppy_tolerance = 34;
+
+var expm1_data_sloppy = [
+    [ 20.11881628179155, 546375092.2355127 ],
+    [ 33.45034324980283, 336743709091858.2 ],
+    [ 46.43974518513109, 147409364838076710000 ],
+    [ 54.60105936314322, 5.163435870507142e+23 ],
+    [ 84.29619209850242, 4.067907545704549e+36 ],
+    [ 125.38131800315817, 2.8340959047812913e+54 ],
+    [ 216.85489905212918, 1.5096839294759775e+94 ],
+];
+
+for (var [x, y] of expm1_data_sloppy)
+    assertNear(Math.expm1(x), y, sloppy_tolerance);
+
 reportCompare(0, 0, "ok");
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/Math/expm1-monotonicity.js
@@ -0,0 +1,94 @@
+var BUGNUMBER = 897634;
+var summary = "expm1 should be monotonically increasing";
+
+print(BUGNUMBER + ": " + summary);
+
+function test(x, prev, next) {
+    assertEq(Math.expm1(prev) <= Math.expm1(x), true);
+    assertEq(Math.expm1(x) <= Math.expm1(next), true);
+}
+
+// Thresholds in fdlibm expm1 implementation.
+
+// |hx| == 0x40862E42 or not
+test(-709.7822265625, -709.7822265625001, -709.7822265624999);
+test(709.7822265625, 709.7822265624999, 709.7822265625001);
+
+// |hx| == 0x4043687A or not
+test(-38.81622314453125, -38.81622314453126, -38.81622314453124);
+test(38.81622314453125, 38.81622314453124, 38.81622314453126);
+
+// |hx| == 0x7ff00000 or not
+test(-1.7976931348623157e+308, -Infinity, -1.7976931348623155e+308);
+test(1.7976931348623157e+308, 1.7976931348623155e+308, Infinity);
+
+// |hx| == 0x3fd62e42 or not
+test(-0.3465733528137207, -0.34657335281372076, -0.34657335281372065);
+test(0.3465733528137207, 0.34657335281372065, 0.34657335281372076);
+
+// |hx| == 0x3FF0A2B2 or not
+test(-1.0397205352783203, -1.0397205352783205, -1.03972053527832);
+test(1.0397205352783203, 1.03972053527832, 1.0397205352783205);
+
+// |hx| == 0x3c900000 or not
+test(-5.551115123125783e-17, -5.551115123125784e-17, -5.551115123125782e-17);
+test(5.551115123125783e-17, 5.551115123125782e-17, 5.551115123125784e-17);
+
+// x < -0.25 or not
+test(-0.25, -0.25000000000000006, -0.24999999999999997);
+
+// k == -1 or k == -2
+test(-1.0397207708399179, -1.039720770839918, -1.0397207708399177);
+
+// k == -1 or k == 0
+test(-0.3465735912322998, -0.34657359123229986, -0.34657359123229975);
+
+// k == 0 or k == 1
+test(0.3465735912322998, 0.34657359123229975, 0.34657359123229986);
+
+// k == 1 or k == 2
+test(1.039720770839918, 1.0397207708399179, 1.0397207708399183);
+
+// k == 19 or k == 20
+test(13.516370020918933, 13.51637002091893, 13.516370020918934);
+
+// k == 56 or k == 57
+test(39.16281570163691, 39.1628157016369, 39.162815701636916);
+
+// k == 1023 or k == 1024
+test(709.436139303104, 709.4361393031039, 709.4361393031041);
+
+// k == 1024 or more
+test(709.7827128933841, 709.782712893384, 709.7827128933842);
+
+// Some more random cases.
+test(-1.7976931348623157e+308, -Infinity, -1.7976931348623155e+308);
+test(-1e+223, -1.0000000000000002e+223, -9.999999999999999e+222);
+test(-1e+100, -1.0000000000000002e+100, -9.999999999999998e+99);
+test(-10000000000, -10000000000.000002, -9999999999.999998);
+test(-100000, -100000.00000000001, -99999.99999999999);
+test(-100, -100.00000000000001, -99.99999999999999);
+test(-10, -10.000000000000002, -9.999999999999998);
+test(-1, -1, -0.9999999999999999);
+test(-0.01, -0.010000000000000002, -0.009999999999999998);
+test(-0.00001, -0.000010000000000000003, -0.000009999999999999999);
+test(-1e-10, -1.0000000000000002e-10, -9.999999999999999e-11);
+test(-1e-100, -1.0000000000000001e-100, -9.999999999999999e-101);
+test(-5e-324, -1e-323, 0);
+test(0, -5e-324, 5e-324);
+test(5e-324, 0, 1e-323);
+test(1e-100, 9.999999999999999e-101, 1.0000000000000001e-100);
+test(1e-10, 9.999999999999999e-11, 1.0000000000000002e-10);
+test(0.00001, 0.000009999999999999999, 0.000010000000000000003);
+test(0.01, 0.009999999999999998, 0.010000000000000002);
+test(1, 0.9999999999999999, 1);
+test(10, 9.999999999999998, 10.000000000000002);
+test(100, 99.99999999999999, 100.00000000000001);
+test(100000, 99999.99999999999, 100000.00000000001);
+test(10000000000, 9999999999.999998, 10000000000.000002);
+test(1e+100, 9.999999999999998e+99, 1.0000000000000002e+100);
+test(1e+223, 9.999999999999999e+222, 1.0000000000000002e+223);
+test(1.7976931348623157e+308, 1.7976931348623155e+308, Infinity);
+
+if (typeof reportCompare === "function")
+    reportCompare(true, true);