mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
330 B
18 lines
330 B
10 years ago
|
'use strict';
|
||
|
|
||
|
var exp = Math.exp;
|
||
|
|
||
|
module.exports = function (x) {
|
||
|
var a, b;
|
||
|
if (isNaN(x)) return NaN;
|
||
|
x = Number(x);
|
||
|
if (x === 0) return x;
|
||
|
if (x === Infinity) return 1;
|
||
|
if (x === -Infinity) return -1;
|
||
|
a = exp(x);
|
||
|
if (a === Infinity) return 1;
|
||
|
b = exp(-x);
|
||
|
if (b === Infinity) return -1;
|
||
|
return (a - b) / (a + b);
|
||
|
};
|