diff --git a/Maths/SquareRoot.js b/Maths/SquareRoot.js index f45118385..3c8f80b2a 100644 --- a/Maths/SquareRoot.js +++ b/Maths/SquareRoot.js @@ -7,6 +7,10 @@ */ function sqrt (num, precision = 10) { + if (!Number.isFinite(num)) + throw new TypeError(`Expected a number, received ${typeof num}`) + if (!Number.isFinite(precision)) + throw new TypeError(`Expected a number, received ${typeof precision}`) let sqrt = 1 for (let i = 0; i < precision; i++) { sqrt -= (sqrt * sqrt - num) / (2 * sqrt)