std::pow with integer parameters, comparing to an integer type

后端 未结 4 1378
天命终不由人
天命终不由人 2020-12-11 20:59

According to http://en.cppreference.com/w/cpp/numeric/math/pow , when std::pow is used with integer parameters, the result is promoted to a double.

4条回答
  •  醉话见心
    2020-12-11 21:44

    For that specific example, it should always return false, especially since you are using type int, so that wouldn't have rounding errors.

    The places where you would want to be cautious about rounding errors is when you're comparing two different arithmetic functions that return floats or doubles with long decimals. Many times they would return as unequal due to different rounding and different operations occurring.

提交回复
热议问题