We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f4e1a56 commit 91efc2cCopy full SHA for 91efc2c
functions/math/log1p.js
@@ -1,6 +1,7 @@
1
function log1p(x) {
2
// discuss at: http://phpjs.org/functions/log1p/
3
// original by: Brett Zamir (http://brett-zamir.me)
4
+ // improved by: Robert Eisele (http://www.xarg.org/)
5
// note: Precision 'n' can be adjusted as desired
6
// example 1: log1p(1e-15);
7
// returns 1: 9.999999999999995e-16
@@ -16,11 +17,7 @@ function log1p(x) {
16
17
return Math.log(1 + x);
18
}
19
for (var i = 1; i < n; i++) {
- if ((i % 2) === 0) {
20
- ret -= Math.pow(x, i) / i;
21
- } else {
22
- ret += Math.pow(x, i) / i;
23
- }
+ ret += Math.pow(-x, i) / i;
24
25
- return ret;
26
-}
+ return -ret;
+}
0 commit comments