I'm trying to make a maths library and one of the functions finds a nth root of a float.
My current expression is -
value = value ^ 1/rootValue
but I'm getting an error because I'm using a float. Is there another method of solving this?
There is no "power" operator in C++; ^
is the bitwise exclusive-or operator, which is only applicable to integers.
Instead, there is a function in the standard library:
#include <cmath>
value = std::pow(value, 1.0/root);
^
is not what you want here. It is a bitwise exclusive-OR operator.
Use
#include <math.h>
and then
value = pow(value, 1/rootvalue)
Reference for pow
: http://www.cplusplus.com/reference/cmath/pow/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With