Skip to content

Commit

Permalink
Replace Math.sign with equivalent since it is not supported everywhere.
Browse files Browse the repository at this point in the history
  • Loading branch information
RayDeCampo committed Oct 16, 2016
1 parent 942419a commit c52d5f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xirr",
"version": "1.0.1",
"version": "1.0.2",
"description": "Compute the internal rate of return of a sequences of transactions made at irregular periods.",
"keywords": [
"xirr",
Expand Down
7 changes: 6 additions & 1 deletion xirr.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ function convert(data) {
};
}

function signum(num) {
return num > 0 ? 1
: num < 0 ? -1 : 0;
}

function xirr(transactions, options) {
var data = convert(transactions);
var investments = data.investments;
Expand All @@ -70,7 +75,7 @@ function xirr(transactions, options) {
}
}, 0);
};
var guess = Math.sign(data.total)/100;
var guess = signum(data.total)/100;
var rate = newton(presentValue, derivative, guess, options);
if (rate === false) { // truthiness strikes again, !rate is true when rate is zero
throw new Error("Newton-Raphson algorithm failed to converge.");
Expand Down

0 comments on commit c52d5f8

Please sign in to comment.