issue 7006 - std.math.pow (integral, integral) crashes on negative exponents
Patrick Schluter
Patrick.Schluter at bbox.fr
Mon Dec 16 15:49:35 UTC 2019
On Monday, 16 December 2019 at 15:33:33 UTC, jmh530 wrote:
> On Monday, 16 December 2019 at 15:13:44 UTC, jmh530 wrote:
>> [snip]
>>
>> What I mean is that if i is 0.5, then you have to return a
>> complex. So you have to add a special case for that.
>
> Simple work-around for the (-1)^^i:
>
> import std;
>
> void main() {
> auto x = iota(10).map!(a => a % 2 ? 1 : -1);
> }
Why can't that pow(int, int) function implement that workaround
and return 0 on all negative exponents and not crash otherwise?
That a function balks at mathematically nonsense values like 1/0
or 0^^0 ok, it's expected. That it does so on a function that
mathematically has valid parameters (even if the result can not
be represented) is not normal. Nobody expects 2^^70 to crash with
divide by 0 error unless explicitly requesting checked integers
that catch overflows.
More information about the Digitalmars-d
mailing list