I have a double which is:
double mydouble = 10;
and I want 10^12, so 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10. I tried
double newDouble = pow(10, 12);
and it returns me in NSLog: pow=-1.991886
makes not much sense... I think pow isn't my friend right?
pow() is function to get the power of a number, but we have to use #include<math. h> in c/c++ to use that pow() function. then two numbers are passed. Example – pow(4 , 2); Then we will get the result as 4^2, which is 16.
The C language lacks an exponentiation operator, which would raise a base value to a certain power. For example: 2^8 , which in some programming languages is an expression to raise 2 to the 8th power. Instead, C uses the pow() function.
C pow() Prototype To find the power of int or a float variable, you can explicitly convert the type to double using cast operator. int base = 3; int power = 5; pow(double(base), double(power));
try pow(10.0, 12.0). Better yet, #include math.h
.
To clarify: If you don't include math.h, the compiler assumes that pow()
returns an integer. Including math.h brings in a prototype like
double pow(double, double);
So the compiler can understand how to treat the arguments and the return value.
I couldn't even get the program to compile without:
#include <math.h>
When using math functions like this you should ALWAYS include math.h and make sure you are calling the right pow function. Who knows what the other pow function might be ... it could stand for "power wheels" haha
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