Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
429 views
in Technique[技术] by (71.8m points)

c - How to raise a double value by power of 12?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...