Skip to content

Commit f4e1a56

Browse files
committed
The equation of tanh() can be simplified a lot
1 parent af32d77 commit f4e1a56

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

functions/math/tanh.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
function tanh(arg) {
22
// discuss at: http://phpjs.org/functions/tanh/
33
// original by: Onno Marsman
4+
// imprived by: Robert Eisele (http://www.xarg.org/)
45
// example 1: tanh(5.4251848798444815);
56
// returns 1: 0.9999612058841574
67

7-
return (Math.exp(arg) - Math.exp(-arg)) / (Math.exp(arg) + Math.exp(-arg));
8+
return 1 - 2 / (Math.exp(2 * arg) + 1);
89
}

0 commit comments

Comments
 (0)