OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 for (var i = -310; i <= 308; i += 0.5) { | 44 for (var i = -310; i <= 308; i += 0.5) { |
45 assertEquals(i, Math.log10(Math.pow(10, i))); | 45 assertEquals(i, Math.log10(Math.pow(10, i))); |
46 // Square roots are tested below. | 46 // Square roots are tested below. |
47 if (i != -0.5 && i != 0.5) assertEquals(i, Math.log2(Math.pow(2, i))); | 47 if (i != -0.5 && i != 0.5) assertEquals(i, Math.log2(Math.pow(2, i))); |
48 } | 48 } |
49 | 49 |
50 // Test denormals. | 50 // Test denormals. |
51 assertEquals(-307.77759430519706, Math.log10(1.5 * Math.pow(2, -1023))); | 51 assertEquals(-307.77759430519706, Math.log10(1.5 * Math.pow(2, -1023))); |
52 | 52 |
| 53 // Issue 4025. Remove delta once issue 4029 has been fixed. |
| 54 assertEqualsDelta(-9.643274665532873e-17, Math.log10(1-Number.EPSILON), 3e-32); |
| 55 |
53 // Test Math.log2(2^k) for -1074 <= k <= 1023. | 56 // Test Math.log2(2^k) for -1074 <= k <= 1023. |
54 var n = -1074; | 57 var n = -1074; |
55 // This loop covers n from -1074 to -1043 | 58 // This loop covers n from -1074 to -1043 |
56 for (var lowbits = 1; lowbits <= 0x80000000; lowbits *= 2) { | 59 for (var lowbits = 1; lowbits <= 0x80000000; lowbits *= 2) { |
57 var x = %_ConstructDouble(0, lowbits); | 60 var x = %_ConstructDouble(0, lowbits); |
58 assertEquals(n, Math.log2(x)); | 61 assertEquals(n, Math.log2(x)); |
59 n++; | 62 n++; |
60 } | 63 } |
61 // This loop covers n from -1042 to -1023 | 64 // This loop covers n from -1042 to -1023 |
62 for (var hibits = 1; hibits <= 0x80000; hibits *= 2) { | 65 for (var hibits = 1; hibits <= 0x80000; hibits *= 2) { |
(...skipping 27 matching lines...) Expand all Loading... |
90 } | 93 } |
91 | 94 |
92 x = Math.pow(2, -100); | 95 x = Math.pow(2, -100); |
93 for (var k = 0; k < 1000; ++k) { | 96 for (var k = 0; k < 1000; ++k) { |
94 var y = Math.log2(x); | 97 var y = Math.log2(x); |
95 var expected = Math.log(x) / Math.LN2; | 98 var expected = Math.log(x) / Math.LN2; |
96 var err = Math.abs(y - expected) / expected; | 99 var err = Math.abs(y - expected) / expected; |
97 assertEqualsDelta(0, err, 1e-15); | 100 assertEqualsDelta(0, err, 1e-15); |
98 x *= 1.1; | 101 x *= 1.1; |
99 } | 102 } |
OLD | NEW |