]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - tests/stress/math-round-arith-rounding-mode.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / math-round-arith-rounding-mode.js
diff --git a/tests/stress/math-round-arith-rounding-mode.js b/tests/stress/math-round-arith-rounding-mode.js
new file mode 100644 (file)
index 0000000..09a2772
--- /dev/null
@@ -0,0 +1,44 @@
+function firstCareAboutZeroSecondDoesNot(a) {
+    var resultA = Math.round(a);
+    var resultB = Math.round(a)|0;
+    return { resultA:resultA, resultB:resultB };
+}
+noInline(firstCareAboutZeroSecondDoesNot);
+
+function firstDoNotCareAboutZeroSecondDoes(a) {
+    var resultA = Math.round(a)|0;
+    var resultB = Math.round(a);
+    return { resultA:resultA, resultB:resultB };
+}
+noInline(firstDoNotCareAboutZeroSecondDoes);
+
+// Warmup with doubles, but nothing that would round to -0 to ensure we never
+// see a double as result. The result must be integers, the input is kept to small values.
+function warmup() {
+    for (var i = 0; i < 1e4; ++i) {
+        firstCareAboutZeroSecondDoesNot(42.6 + i);
+        firstDoNotCareAboutZeroSecondDoes(42.4 + i);
+    }
+}
+warmup();
+
+function verifyNegativeZeroIsPreserved() {
+    for (var i = 0; i < 1e4; ++i) {
+        var result1 = firstCareAboutZeroSecondDoesNot(-0.1);
+        if (1 / result1.resultA !== -Infinity) {
+            throw "Failed firstCareAboutZeroSecondDoesNot(-0.1), resultA = " + result1.resultA;
+        }
+        if (1 / result1.resultB !== Infinity) {
+            throw "Failed firstCareAboutZeroSecondDoesNot(-0.1), resultB = " + result1.resultB;
+        }
+        var result2 = firstDoNotCareAboutZeroSecondDoes(-0.1);
+        if (1 / result2.resultA !== Infinity) {
+            throw "Failed firstDoNotCareAboutZeroSecondDoes(-0.1), resultA = " + result1.resultA;
+        }
+        if (1 / result2.resultB !== -Infinity) {
+            throw "Failed firstDoNotCareAboutZeroSecondDoes(-0.1), resultB = " + result1.resultB;
+        }
+
+    }
+}
+verifyNegativeZeroIsPreserved();
\ No newline at end of file