issue 7006 - std.math.pow (integral, integral) crashes on negative exponents
Timon Gehr
timon.gehr at gmx.ch
Wed Dec 18 00:37:40 UTC 2019
On Wednesday, 18 December 2019 at 00:03:14 UTC, Ola Fosheim
Grøstad wrote:
> On Tuesday, 17 December 2019 at 23:29:53 UTC, Timon Gehr wrote:
>> ...
>> on x86. For instance, if I added a single special case for
>> std::pow(0.0,0.0) to a standards-compliant C++17
>> implementation for x86-64 with floating-point support, which
>> values could I return without breaking C++17 standard
>> compliance?)
>
> Whatever you like. It is implementation defined. That does
> not mean it is encouraged to return something random.
> ...
"If a domain error occurs, an implementation-defined value is
returned (NaN where supported)"
I.e., what you are saying is that even if the implementation
supports NaN, it may return non-NaN, the above statement
notwithstanding?
> According to the standard x^y is defined as:
>
> exp(y * log(x))
> ...
Well, that's pretty lazy. Also, it can't be true simultaneously
with your claim that pow(0.0,0.0) can be modified to return
_anything_, as it would then need to be consistent with
exp(0.0*log(0.0)).
Also:
$ cat test.cpp
#include <cmath>
#include <iostream>
using namespace std;
int main(){
cout<<pow(0.0,0.0)<<endl; // 1
cout<<exp(0.0*log(0.0))<<endl; // -nan
double x=328.78732, y=36.3; // (random values I entered)
cout<<(pow(x,y)==exp(y*log(x)))<<endl; // 0
}
$ g++ -std=c++11 -m64 -pedantic test.cpp && ./a.out
1
-nan
0
I may soon just go back to ignoring all your posts (like Walter
also does).
More information about the Digitalmars-d
mailing list