issue 7006 - std.math.pow (integral, integral) crashes on negative exponents
Dominikus Dittes Scherkl
dominikus.scherkl at continental-corporation.com
Mon Dec 16 06:44:31 UTC 2019
On Monday, 16 December 2019 at 03:20:32 UTC, mipri wrote:
> You expect some specific behavior of pow(), but what do you
> expect of functions like pow in general? What principle does
> pow() violate by having this weirdly implemented domain
> restriction? Would you be satisfied if the line were changed to
>
> enforce(n >= 0, "only natural powers are supported");
>
> or
>
> assert(n >= 0);
>
> or
>
> @deprecated("use floating point pow instead")
In this special case, I would think changing the function
signature to take only "uint" as exponent would be sufficient. If
you need negative exponents using the floating point pow is more
useful anyway.
Of course -1^^x is a useful function, but if you need it, I would
still think using floating point makes more sense. And if its
time critical and you need only integers, there are much faster
solutions than using pow (e.g. odd(x)?-1:1 )
More information about the Digitalmars-d
mailing list