issue 7006 - std.math.pow (integral, integral) crashes on negative exponents

Timon Gehr timon.gehr at gmx.ch
Wed Dec 18 04:07:39 UTC 2019


On 18.12.19 04:29, Timon Gehr wrote:
> So I guess the C++ standard (like IEEE floating point) does not require 
> exact rounding for some transcendental functions, most likely including pow.

It seems IEEE 754 recommends exactly rounded `pow`, but it is not 
required for conformance (but `pow(0.0,0.0)==1.0` is required).

Also, I finally found this: 
https://en.cppreference.com/w/cpp/numeric/math/sqrt

"Notes
std::sqrt is required by the IEEE standard to be exact. The only other 
operations required to be exact are the arithmetic operators and the 
function std::fma. After rounding to the return type (using default 
rounding mode), the result of std::sqrt is indistinguishable from the 
infinitely precise result. In other words, the error is less than 0.5 
ulp. Other functions, including std::pow, are not so constrained."

What a weird place to hide this information. I guess I was wrong about 
C++11 `pow(0.0,0.0)` being _required_ to return either 1.0 or NaN. Sorry 
about that. (However, any implementation that chooses to implement `pow` 
conforming to IEEE 754 will return `1.0`.)

Unfortunately, none of this is actually relevant for the case of D's 
`pow(int,int)`.


More information about the Digitalmars-d mailing list