Skip to content

Commit

Permalink
Merge pull request #58 from nicolashefti/log-bug
Browse files Browse the repository at this point in the history
Fix base 10 as default for LOG function
  • Loading branch information
Y authored Apr 12, 2017
2 parents b1174ee + 575e9ee commit ca833f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/math-trig.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,12 @@ exports.LN = function(number) {

exports.LOG = function(number, base) {
number = utils.parseNumber(number);
base = utils.parseNumber(base);
base = (base === undefined) ? 10 : utils.parseNumber(base);

if (utils.anyIsError(number, base)) {
return error.value;
}
base = (base === undefined) ? 10 : base;

return Math.log(number) / Math.log(base);
};

Expand Down Expand Up @@ -1105,4 +1106,4 @@ exports.TRUNC = function(number, digits) {
}
var sign = (number > 0) ? 1 : -1;
return sign * (Math.floor(Math.abs(number) * Math.pow(10, digits))) / Math.pow(10, digits);
};
};
3 changes: 2 additions & 1 deletion test/math-trig.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ suite('Math & Trig', function() {
});

test('LOG', function() {
mathTrig.LOG(10).should.equal(1);
mathTrig.LOG(10, 10).should.equal(1);
mathTrig.LOG(10, 'invalid').should.equal(error.value);
});
Expand Down Expand Up @@ -795,4 +796,4 @@ suite('Math & Trig', function() {
mathTrig.TRUNC(0.45).should.equal(0);
mathTrig.TRUNC('invalid').should.equal(error.value);
});
});
});

0 comments on commit ca833f2

Please sign in to comment.