We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e5b5cf6 commit bbdf16fCopy full SHA for bbdf16f
Maths/PerfectCube.js
@@ -1,11 +1,12 @@
1
/**
2
* Author: dephraiim
3
* License: GPL-3.0 or later
4
- *
5
- * Infinity is an undefined cube, so return false for any sign.
6
- * This uses `round` instead of `floor` or `trunc`, to guard against rounding errors.
+ *
+ * The integer check acts as a guard clause, and avoids calculating the root if the input is invalid,
+ * it also ensures Infinity is treated as a non-cube.
7
+ * This uses `round` instead of `floor` or `trunc`, to guard against potential `cbrt` accuracy errors.
8
*/
9
-const perfectCube = (num) => Number.isFinite(num) && Math.round(Math.cbrt(num)) ** 3 === num
10
+const perfectCube = (num) => Number.isInteger(num) && Math.round(Math.cbrt(num)) ** 3 === num
11
12
export { perfectCube }
0 commit comments