Math Cubic Root function?
-
As the title says, I couldn't find a cubic root function equivalent to
std::cbrt
Any ideas?
-
@JulesV
Math.pow(x, 1/3);
? -
@d-healey Yes, that's it, thanks. I had to use If/else Statement for negative values, though.
-
@JulesV abs is your friend here.
-
@JulesV What about something like this
inline function cubeRoot(x) { return x < 0 ? -Math.pow(-x, 1/3) : Math.pow(x, 1/3); }
-
@d-healey or this
return Math.sign(x) * Math.pow(Math.abs(x), 1/3);
But a benchmark shows no difference in efficiency