Skip to content

Commit

Permalink
Add precision tests and a fix for Math.cosh and Math.sinh.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 17, 2015
1 parent cf344e3 commit 6710cd7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -1225,9 +1225,13 @@
},

sinh: function (value) {
value = Number(value);
var x = Number(value);
if (!global_isFinite(value) || value === 0) { return value; }
return (Math.exp(value) - Math.exp(-value)) / 2;

if (Math.abs(x) < 1) {
return (Math.expm1(x) - Math.expm1(-x)) / 2;
}
return (Math.exp(x - 1) - Math.exp(-x - 1)) * Math.E / 2;
},

tanh: function (value) {
Expand Down
2 changes: 2 additions & 0 deletions test/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ describe('Math', function () {
expect(Math.cosh(22)).to.almostEqual(1792456423.065795780980053377, 1e-5);
expect(Math.cosh(-10)).to.almostEqual(11013.23292010332313972137);
expect(Math.cosh(-23)).to.almostEqual(4872401723.1244513000, 1e-5);
expect(Math.cosh(-2e-17)).to.equal(1);
});
});

Expand Down Expand Up @@ -315,6 +316,7 @@ describe('Math', function () {
expect(Math.sinh(-Infinity)).to.equal(-Infinity);
expect(Math.sinh(-5)).to.almostEqual(-74.20321057778875);
expect(Math.sinh(2)).to.almostEqual(3.6268604078470186);
expect(Math.sinh(-2e-17)).to.equal(-2e-17);
});
});

Expand Down

0 comments on commit 6710cd7

Please sign in to comment.