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

Dominikus Dittes Scherkl dominikus.scherkl at continental-corporation.com
Tue Dec 17 15:07:40 UTC 2019


On Tuesday, 17 December 2019 at 14:26:42 UTC, Timon Gehr wrote:
> On 17.12.19 14:39, Dominikus Dittes Scherkl wrote:
>> ^^ should result in a real if the exponent is outside ubyte 
>> range.
>> Is this wrong?
>
> Yes.
Why? It's highly likely that the result is out of range or is a 
fraction.
A floatginpoint value would give much more useful information.

> There are reasonable outputs for the entire range of each 
> individual argument.

If you look at it from mathematical point of view:
pow is defined as a mapping
ℕ × ℕ → ℕ
but if we extend it to
ℤ × ℤ → ℤ
we have undefined points, because 1/n is not in ℤ for all n>1.
Maybe it is convenient to return 0 in such cases, but not correct.
Throwing is more plausible, if restricting to ℤ × ℕ → ℤ or
extending to ℤ × ℤ → ℚ is wrong as you state above.

> I'd highly prefer it to consistently return 0 rather than kill 
> my program without a stack trace. However, I agree that this 
> case is slightly less clear-cut.
At least it is not what I would call "consistent".

Meanwhile I looked at the implementation and it has more places 
to optimize.
E.g. it should give 1 for any value x^^0, not only for 0^^0 
(nothing to calc here)
also all comments talk about n for the exponent, while in fact m 
is used in the code.



More information about the Digitalmars-d mailing list