Skip to content

Commit

Permalink
Add support for logarithmic functions
Browse files Browse the repository at this point in the history
- log(x): base 10
- ln(x): base e
  • Loading branch information
heokhe committed Apr 2, 2021
1 parent 58d8bcc commit 58c6e6d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const trigonometric = require('./trigonometric');

module.exports = {
...trigonometric,
ln: Math.log,
log: Math.log10,
cbrt: Math.cbrt,
sqrt: Math.sqrt,
abs: Math.abs,
Expand Down
5 changes: 5 additions & 0 deletions tests/calc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ tap.equals(evalExpression('cos(270)'), 0);

// trigonometric functions: tan & cot
tap.equals(evalExpression('cot(4)'), 1 / evalExpression('tan(4)'));

// logarithmic functions
tap.equals(evalExpression('log(100)'), 2);
tap.equals(evalExpression('ln(1)'), 0);
tap.equals(evalExpression('log(64) / log(8)'), 2);

0 comments on commit 58c6e6d

Please sign in to comment.