How to increase the double value by force 12?

I have a double that:

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 he returns me to NSLog: pow=-1.991886

doesn't make much sense ... I think pow is not my friend?

+4
source share
5 answers

try pow (10.0, 12.0). Even better, #include math.h

To clarify: if you do not include math.h , the compiler assumes that pow() returns an integer. Including math.h contains a prototype, for example

 double pow(double, double); 

So, the compiler can figure out how to handle the arguments and return value.

+12
source

I could not even compile the program:

 #include <math.h> 

When using math functions like this, you should ALWAYS include math.h and make sure you call the correct pow function. Who knows what could be another function of pow ... it could mean "power wheels" haha

+5
source

Here's how to calculate x ^ 12 with the least number of multiplications.

 y = x*x*x; y *= y; y *= y; 

The method comes from Knuth Seven-Dimensional Algorithms , section 4.6.3.

+4
source

What is the correct syntax for pow, which format string do you pass to NSLog (...)?

0
source

You tried casting in double:

 NSLog(@"(double)pow(10, 12) = %lf", (double)pow(10, 12)); 
0
source

All Articles