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

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Mon Dec 16 14:27:16 UTC 2019


On Monday, 16 December 2019 at 13:53:06 UTC, M.M. wrote:
> So, while determinants or binomial coefficients do not use 
> naturally (-1)^i with negative value of i, there are other 
> cases (which Timon probably referred to) in combinatorics, 
> where using (-1)^i with negative value comes naturally.

It is easy to implement, isn't it?
But what would you optimize for?

Would you make x^i = 0  a bit faster for i < 0  in the general 
case?
Or would you test for -1 and special case it for significant 
speedups?

Without special casing it will be slow:

(-1)^(-1) = 1/((-1)^1 ) = -1
(-1)^(-2) = 1/((-1)^2) = 1
(-1)^(-3) = 1/((-1)^3) = -1

With special casing you get: 1 - ((i&1)<<1) or something like 
that.
(1-2 and 1-0)


More information about the Digitalmars-d mailing list