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

前端 未结 11 1384
礼貌的吻别
礼貌的吻别 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 03:10

    A very simple reason:

    5^-2 = 1/25
    

    Everything in the STL library is based on the most accurate, robust stuff imaginable. Sure, the int would return to a zero (from 1/25) but this would be an inaccurate answer.

    I agree, it's weird in some cases.

提交回复
热议问题