v8/test/mjsunit/es6/math-cbrt.js
yangguo@chromium.org d1333142e2 Ship ES6 Math functions.
R=rossberg@chromium.org
BUG=v8:2938
LOG=Y

Review URL: https://codereview.chromium.org/394833002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22434 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-16 14:00:15 +00:00

26 lines
938 B
JavaScript

// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
assertTrue(isNaN(Math.cbrt(NaN)));
assertTrue(isNaN(Math.cbrt(function() {})));
assertTrue(isNaN(Math.cbrt({ toString: function() { return NaN; } })));
assertTrue(isNaN(Math.cbrt({ valueOf: function() { return "abc"; } })));
assertEquals("Infinity", String(1/Math.cbrt(0)));
assertEquals("-Infinity", String(1/Math.cbrt(-0)));
assertEquals("Infinity", String(Math.cbrt(Infinity)));
assertEquals("-Infinity", String(Math.cbrt(-Infinity)));
for (var i = 1E-100; i < 1E100; i *= Math.PI) {
assertEqualsDelta(i, Math.cbrt(i*i*i), i * 1E-15);
}
for (var i = -1E-100; i > -1E100; i *= Math.E) {
assertEqualsDelta(i, Math.cbrt(i*i*i), -i * 1E-15);
}
// Let's be exact at least for small integers.
for (var i = 2; i < 10000; i++) {
assertEquals(i, Math.cbrt(i*i*i));
}