Skip to content

Commit

Permalink
added exp
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Nov 20, 2022
1 parent ffb0248 commit e915d6d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ divide("-714.7008086132632", "8135.725531"); // -714.7008086132632 / 8135.725531
'-0.0878472123832102762218908980055167989417759034280282678823325216230183564682007707223868489179001533'
```

### exp
Raise [Euler's Number](https://en.wikipedia.org/wiki/E_(mathematical_constant)) to the given power
```js
import exp from "preciso/exp.js";

exp("-Infinity") // "0"
exp("-1") // "0.3678794411714423..."
exp("0") // "1"
exp("1") // "2.718281828459045..."
exp("2") // "7.389056098930650..."
exp("10") // "22026.46579480671..."
exp("Infinity") // "Infinity"
```

### factorial
```js
import factorial from "preciso/factorial.js";
Expand Down
21 changes: 21 additions & 0 deletions exp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const clean = require("./clean.js");
const is_negative_infinity = require("./is_negative_infinity.js");
const is_positive_infinity = require("./is_positive_infinity.js");
const is_zero = require("./is_zero.js");
const eulers_number = require("./eulers_number.js");
const pow = require("./pow.js");

function exp(power, { max_decimal_digits } = {}) {
const e = eulers_number(100);

if (is_negative_infinity(power)) return "0";
if (is_positive_infinity(power)) return "Infinity";
if (is_zero(power)) return "1";

power = clean(power);

return pow(e, power, { max_decimal_digits });
}

module.exports = exp;
module.exports.default = exp;

0 comments on commit e915d6d

Please sign in to comment.