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

Timon Gehr timon.gehr at gmx.ch
Wed Dec 18 02:44:49 UTC 2019


On 18.12.19 03:30, Timon Gehr wrote:
> On 18.12.19 03:14, Timon Gehr wrote:
>>
>> Perhaps what you mean to say is that the C++ standard is understood to 
>> be so lax that it doesn't actually define the expected result of pow 
>> for anything but the listed special cases, such that pedantically 
>> speaking, pow could return NaN (or, usually, any other value) for all 
>> other pairs of arguments (usually, without raising a domain error)?
> 
> Reviewing this page, this does not appear to be the case either:
> https://en.cppreference.com/w/cpp/numeric/fenv/FE_round
> 
> So I guess I still don't understand why you think an implementation 
> could return an arbitrary value.

The following simple test that would have been able to refute my 
interpretation of the standard failed to do so:

#include <cmath>
#include <cfenv>
#include <iostream>
using namespace std;

int main(){
     #pragma STDC FENV_ACCESS ON
     double x=328.78732,y=36.3;
     fesetround(FE_DOWNWARD);
     double r1=pow(x,y);
     fesetround(FE_UPWARD);
     double r2=pow(x,y);
     cout<<*(unsigned long long*)&r1<<endl; // 5973659313751886762
     cout<<*(unsigned long long*)&r2<<endl; // 5973659313751886763
}

(Of course, this is not by itself enough to show that my interpretation 
is right.)


More information about the Digitalmars-d mailing list