How to raise a double value by power of 12?

后端 未结 5 1083
谎友^
谎友^ 2020-12-11 06:49

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

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-11 06:57

    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.

提交回复
热议问题