Skip to content

Commit

Permalink
added $root
Browse files Browse the repository at this point in the history
  • Loading branch information
baka-aho authored Dec 22, 2023
1 parent 59a136d commit 51022b4
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/functions/math/root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = d => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);

const [number, root] = data.inside.splits;

if (isNaN(number) || number.trim() === '') return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid Number Provided In');
if (isNaN(root) || root.trim() === '') return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid Root Number Provided In');

data.result = number < 0 && root % 2 === 0 ? NaN : Math.pow(Number(number), 1 / Number(root));

return {
code: d.util.setCode(data)
}
}

0 comments on commit 51022b4

Please sign in to comment.