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

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Wed Dec 18 00:12:19 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:
>> what it says on the page? (Please no more pointless 
>> elaborations on what common terms mean,
>
> Well, «may» have other connotations in standard texts that in 
> oridinary language, so I read such texts differently than you, 
> obviously.
>
>
>> 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?)

Please note that you can test for 60559.212 conformance at 
compile time using:

static constexpr bool is_iec559;

57 true if and only if the type adheres to ISO/IEC/IEEE 60559.212
58 Meaningful for all floating-point types.

Which gives guarantees:

For the pown function (integral exponents only):
pown(x, 0) is 1 for any x (even a zero, quiet NaN, or infinity)
pown(±0, n) is ±∞ and signals the divideByZero exception for odd 
integral n<0
pown(±0, n) is +∞ and signals the divideByZero exception for even 
integral n<0
pown(±0, n) is +0 for even integral n>0
pown(±0, n) is ±0 for odd integral n>0.

For the pow function (integral exponents get special treatment):
pow(x, ±0) is 1 for any x (even a zero, quiet NaN, or infinity)
pow(±0, y) is ±∞ and signals the divideByZero exception for y an 
odd integer <0
pow(±0, −∞) is +∞ with no exception
pow(±0, +∞) is +0 with no exception
pow(±0, y) is +∞ and signals the divideByZero exception for 
finite y<0 and not an odd integer
pow(±0, y) is ±0 for finite y>0 an odd integer
pow(±0, y) is +0 for finite y>0 and not an odd integer
pow(−1, ±∞) is 1 with no exception
pow(+1, y) is 1 for any y (even a quiet NaN)
pow(x, y) signals the invalid operation exception for finite x<0 
and finite non-integer y.

For the powr function (derived by considering only exp(y×log(x))):
powr(x, ±0) is 1 for finite x>0
powr(±0, y) is +∞ and signals the divideByZero exception for 
finite y<0
powr(±0, −∞) is +∞
powr(±0, y) is +0 for y>0
powr(+1, y) is 1 for finite y
powr(x, y) signals the invalid operation exception for x<0
powr(±0, ±0) signals the invalid operation exception
powr(+∞, ±0) signals the invalid operation exception
powr(+1, ±∞) signals the invalid operation exception
powr(x, qNaN) is qNaN for x≥0
powr(qNaN, y) is qNaN.






More information about the Digitalmars-d mailing list