Skip to content

Commit bbdf16f

Browse files
authored
Update PerfectCube.js
1 parent e5b5cf6 commit bbdf16f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Maths/PerfectCube.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/**
22
* Author: dephraiim
33
* 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.
4+
*
5+
* The integer check acts as a guard clause, and avoids calculating the root if the input is invalid,
6+
* 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.
78
*/
89

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
1011

1112
export { perfectCube }

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy