Why isn't `int pow(int base, int exponent)` in the standard C++ libraries?

前端 未结 11 1348
礼貌的吻别
礼貌的吻别 2020-11-27 02:20

I feel like I must just be unable to find it. Is there any reason that the C++ pow function does not implement the \"power\" function for anything except

11条回答
  •  死守一世寂寞
    2020-11-27 02:59

    As a matter of fact, it does.

    Since C++11 there is a templated implementation of pow(int, int) --- and even more general cases, see (7) in http://en.cppreference.com/w/cpp/numeric/math/pow


    EDIT: purists may argue this is not correct, as there is actually "promoted" typing used. One way or another, one gets a correct int result, or an error, on int parameters.

提交回复
热议问题