OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --harmony-maths | |
6 | |
7 assertTrue(isNaN(Math.cbrt(NaN))); | 5 assertTrue(isNaN(Math.cbrt(NaN))); |
8 assertTrue(isNaN(Math.cbrt(function() {}))); | 6 assertTrue(isNaN(Math.cbrt(function() {}))); |
9 assertTrue(isNaN(Math.cbrt({ toString: function() { return NaN; } }))); | 7 assertTrue(isNaN(Math.cbrt({ toString: function() { return NaN; } }))); |
10 assertTrue(isNaN(Math.cbrt({ valueOf: function() { return "abc"; } }))); | 8 assertTrue(isNaN(Math.cbrt({ valueOf: function() { return "abc"; } }))); |
11 assertEquals("Infinity", String(1/Math.cbrt(0))); | 9 assertEquals("Infinity", String(1/Math.cbrt(0))); |
12 assertEquals("-Infinity", String(1/Math.cbrt(-0))); | 10 assertEquals("-Infinity", String(1/Math.cbrt(-0))); |
13 assertEquals("Infinity", String(Math.cbrt(Infinity))); | 11 assertEquals("Infinity", String(Math.cbrt(Infinity))); |
14 assertEquals("-Infinity", String(Math.cbrt(-Infinity))); | 12 assertEquals("-Infinity", String(Math.cbrt(-Infinity))); |
15 | 13 |
16 for (var i = 1E-100; i < 1E100; i *= Math.PI) { | 14 for (var i = 1E-100; i < 1E100; i *= Math.PI) { |
17 assertEqualsDelta(i, Math.cbrt(i*i*i), i * 1E-15); | 15 assertEqualsDelta(i, Math.cbrt(i*i*i), i * 1E-15); |
18 } | 16 } |
19 | 17 |
20 for (var i = -1E-100; i > -1E100; i *= Math.E) { | 18 for (var i = -1E-100; i > -1E100; i *= Math.E) { |
21 assertEqualsDelta(i, Math.cbrt(i*i*i), -i * 1E-15); | 19 assertEqualsDelta(i, Math.cbrt(i*i*i), -i * 1E-15); |
22 } | 20 } |
23 | 21 |
24 // Let's be exact at least for small integers. | 22 // Let's be exact at least for small integers. |
25 for (var i = 2; i < 10000; i++) { | 23 for (var i = 2; i < 10000; i++) { |
26 assertEquals(i, Math.cbrt(i*i*i)); | 24 assertEquals(i, Math.cbrt(i*i*i)); |
27 } | 25 } |
OLD | NEW |