For odd numbered roots (e.g. cubic) and negative numbers, the root result is well defined and negative, but just using pow(value, 1.0/n) doesn't work (you return NaN - not a number).
So use this instead:
int f = (value < 0 && (n % 2 == 1)) ? -1 : 1; root = pow(value * f, 1.0/n) * f
flo von der uni
source share