]> gerrit.simantics Code Review - simantics/district.git/blob - tanh/shim.js
Hide "enabled" column for non-component type tech type tables
[simantics/district.git] / tanh / shim.js
1 'use strict';
2
3 var exp = Math.exp;
4
5 module.exports = function (x) {
6         var a, b;
7         if (isNaN(x)) return NaN;
8         x = Number(x);
9         if (x === 0) return x;
10         if (x === Infinity) return 1;
11         if (x === -Infinity) return -1;
12         a = exp(x);
13         if (a === Infinity) return 1;
14         b = exp(-x);
15         if (b === Infinity) return -1;
16         return (a - b) / (a + b);
17 };