X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/2d39b0e377c0896910ee49ae70082ba665faf986..ed1e77d3adeb83d26fd1dfb16dd84cabdcefd250:/tests/stress/math-log-with-constants.js diff --git a/tests/stress/math-log-with-constants.js b/tests/stress/math-log-with-constants.js new file mode 100644 index 0000000..c05a075 --- /dev/null +++ b/tests/stress/math-log-with-constants.js @@ -0,0 +1,128 @@ +// Basic cases of Math.log() when the value passed are constants. + +// log(NaN). +function logNaN() { + return Math.log(NaN); +} +noInline(logNaN); + +function testLogNaN() { + for (var i = 0; i < 10000; ++i) { + var result = logNaN(); + if (!isNaN(result)) + throw "logNaN() = " + result + ", expected NaN"; + } +} +testLogNaN(); + + +// log(0). +function logZero() { + return Math.log(0); +} +noInline(logZero); + +function testLogZero() { + for (var i = 0; i < 10000; ++i) { + var result = logZero(); + if (result !== -Infinity) + throw "logZero() = " + result + ", expected -Infinity"; + } +} +testLogZero(); + + +// log(1). +function logOne() { + return Math.log(1); +} +noInline(logOne); + +function testLogOne() { + for (var i = 0; i < 10000; ++i) { + var result = logOne(); + if (result !== 0) + throw "logOne(1) = " + result + ", expected 0"; + } +} +testLogOne(); + + +// log(-1). +function logMinusOne() { + return Math.log(-1); +} +noInline(logMinusOne); + +function testLogMinusOne() { + for (var i = 0; i < 10000; ++i) { + var result = logMinusOne(); + if (!isNaN(result)) + throw "logMinusOne() = " + result + ", expected NaN"; + } +} +testLogMinusOne(); + + +// log(Infinity). +function logInfinity() { + return Math.log(Infinity); +} +noInline(logInfinity); + +function testLogInfinity() { + for (var i = 0; i < 10000; ++i) { + var result = logInfinity(); + if (result !== Infinity) + throw "logInfinity() = " + result + ", expected Infinity"; + } +} +testLogInfinity(); + + +// log(-Infinity). +function logMinusInfinity() { + return Math.log(-Infinity); +} +noInline(logMinusInfinity); + +function testLogMinusInfinity() { + for (var i = 0; i < 10000; ++i) { + var result = logMinusInfinity(); + if (!isNaN(result)) + throw "logMinusInfinity() = " + result + ", expected NaN"; + } +} +testLogMinusInfinity(); + + +// log(integer). +function logInteger() { + return Math.log(42); +} +noInline(logInteger); + +function testLogInteger() { + for (var i = 0; i < 10000; ++i) { + var result = logInteger(); + if (result !== 3.7376696182833684) + throw "logInteger() = " + result + ", expected 3.7376696182833684"; + } +} +testLogInteger(); + + +// log(double). +function logDouble() { + return Math.log(Math.PI); +} +noInline(logDouble); + +function testLogDouble() { + for (var i = 0; i < 10000; ++i) { + var result = logDouble(); + if (result !== 1.1447298858494002) + throw "logDouble() = " + result + ", expected 1.1447298858494002"; + } +} +testLogDouble(); \ No newline at end of file