Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Side by Side Diff: test/mjsunit/harmony/math-expm1.js

Issue 163563003: Harmony: implement Math.cbrt, Math.expm1 and Math.log1p. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: uploaded new Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/harmony/math-cbrt.js ('k') | test/mjsunit/harmony/math-log1p.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 // Flags: --harmony-maths --no-fast-math
6
7 assertTrue(isNaN(Math.expm1(NaN)));
8 assertTrue(isNaN(Math.expm1(function() {})));
9 assertTrue(isNaN(Math.expm1({ toString: function() { return NaN; } })));
10 assertTrue(isNaN(Math.expm1({ valueOf: function() { return "abc"; } })));
11 assertEquals("Infinity", String(1/Math.expm1(0)));
12 assertEquals("-Infinity", String(1/Math.expm1(-0)));
13 assertEquals("Infinity", String(Math.expm1(Infinity)));
14 assertEquals(-1, Math.expm1(-Infinity));
15
16 for (var x = 0.1; x < 700; x += 0.1) {
17 var expected = Math.exp(x) - 1;
18 assertEqualsDelta(expected, Math.expm1(x), expected * 1E-14);
19 expected = Math.exp(-x) - 1;
20 assertEqualsDelta(expected, Math.expm1(-x), -expected * 1E-14);
21 }
22
23 // Values close to 0:
24 // Use six terms of Taylor expansion at 0 for exp(x) as test expectation:
25 // exp(x) - 1 == exp(0) + exp(0) * x + x * x / 2 + ... - 1
26 // == x + x * x / 2 + x * x * x / 6 + ...
27 function expm1(x) {
28 return x * (1 + x * (1/2 + x * (
29 1/6 + x * (1/24 + x * (
30 1/120 + x * (1/720 + x * (
31 1/5040 + x * (1/40320 + x*(
32 1/362880 + x * (1/3628800))))))))));
33 }
34
35 for (var x = 1E-1; x > 1E-300; x *= 0.8) {
36 var expected = expm1(x);
37 assertEqualsDelta(expected, Math.expm1(x), expected * 1E-14);
38 }
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/math-cbrt.js ('k') | test/mjsunit/harmony/math-log1p.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698