| Index: test/mjsunit/es6/math-log2-log10.js
|
| diff --git a/test/mjsunit/es6/math-log2-log10.js b/test/mjsunit/es6/math-log2-log10.js
|
| index 863506c7055d77127d4694a6c461fc54a7b28d4e..fa3f46807a10169ec36b99297ae24cf0fd080e1c 100644
|
| --- a/test/mjsunit/es6/math-log2-log10.js
|
| +++ b/test/mjsunit/es6/math-log2-log10.js
|
| @@ -25,6 +25,8 @@
|
| // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
| +// Flags: --allow-natives-syntax
|
| +
|
| [Math.log10, Math.log2].forEach( function(fun) {
|
| assertTrue(isNaN(fun(NaN)));
|
| assertTrue(isNaN(fun(fun)));
|
| @@ -41,8 +43,57 @@
|
|
|
| for (var i = -310; i <= 308; i += 0.5) {
|
| assertEquals(i, Math.log10(Math.pow(10, i)));
|
| - assertEqualsDelta(i, Math.log2(Math.pow(2, i)), 1E-13);
|
| + // Square roots are tested below.
|
| + if (i != -0.5 && i != 0.5) assertEquals(i, Math.log2(Math.pow(2, i)));
|
| }
|
|
|
| // Test denormals.
|
| assertEquals(-307.77759430519706, Math.log10(1.5 * Math.pow(2, -1023)));
|
| +
|
| +// Test Math.log2(2^k) for -1074 <= k <= 1023.
|
| +var n = -1074;
|
| +// This loop covers n from -1074 to -1043
|
| +for (var lowbits = 1; lowbits <= 0x80000000; lowbits *= 2) {
|
| + var x = %_ConstructDouble(0, lowbits);
|
| + assertEquals(n, Math.log2(x));
|
| + n++;
|
| +}
|
| +// This loop covers n from -1042 to -1023
|
| +for (var hibits = 1; hibits <= 0x80000; hibits *= 2) {
|
| + var x = %_ConstructDouble(hibits, 0);
|
| + assertEquals(n, Math.log2(x));
|
| + n++;
|
| +}
|
| +// The rest of the normal values of 2^n
|
| +var x = 1;
|
| +for (var n = -1022; n <= 1023; ++n) {
|
| + var x = Math.pow(2, n);
|
| + assertEquals(n, Math.log2(x));
|
| +}
|
| +
|
| +// Test special values.
|
| +// Expectation isn't exactly 1/2 because Math.SQRT2 isn't exactly sqrt(2).
|
| +assertEquals(0.5000000000000001, Math.log2(Math.SQRT2));
|
| +
|
| +// Expectation isn't exactly -1/2 because Math.SQRT1_2 isn't exactly sqrt(1/2).
|
| +assertEquals(-0.4999999999999999, Math.log2(Math.SQRT1_2));
|
| +
|
| +assertEquals(3.321928094887362, Math.log2(10));
|
| +assertEquals(6.643856189774724, Math.log2(100));
|
| +
|
| +// Test relationships
|
| +x = 1;
|
| +for (var k = 0; k < 1000; ++k) {
|
| + var y = Math.abs(Math.log2(x) + Math.log2(1/x));
|
| + assertEqualsDelta(0, y, 1.5e-14);
|
| + x *= 1.1;
|
| +}
|
| +
|
| +x = Math.pow(2, -100);
|
| +for (var k = 0; k < 1000; ++k) {
|
| + var y = Math.log2(x);
|
| + var expected = Math.log(x) / Math.LN2;
|
| + var err = Math.abs(y - expected) / expected;
|
| + assertEqualsDelta(0, err, 1e-15);
|
| + x *= 1.1;
|
| +}
|
|
|