paulmillr / es6-shim

ECMAScript 6 compatibility shims for legacy JS engines
http://paulmillr.com
MIT License
3.11k stars 387 forks source link

Simplify logic for Math.tanh #412

Closed benjoffe closed 8 years ago

benjoffe commented 8 years ago

Previous PR for tanh left some code that was no longer needed (the checks against Infinity are redundant with the early exit).

benjoffe commented 8 years ago

You're correct about neglibile performance difference for Math.sign changes, reverted.

ljharb commented 8 years ago

Thanks, this looks great - if it's not too much to ask, could you rebase this on latest master?

Yaffle commented 8 years ago
Math.tanh = function (x) {
  return Math.sign(x) / (1 + 2 / Math.expm1(2 * Math.abs(x)));
};

What about this one?

ljharb commented 8 years ago

@Yaffle i'd be happy to review a new PR that changed the implementation, with assorted tests (altho i'd prefer the edge cases be explicit)