issue 7006 - std.math.pow (integral, integral) crashes on negative exponents
jmh530
john.michael.hall at gmail.com
Mon Dec 16 15:00:47 UTC 2019
On Monday, 16 December 2019 at 13:53:06 UTC, M.M. wrote:
> [snip]
>
> In my comment, "i" stands for an iterator (in a for-loop, for
> example), and not for a complex number.
>
> But I also see that my answer stressed the usefulness of (-1)^i
> for the cases where i is a _positive_ integer, which is not the
> part of this discussion.
>
> 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.
I don't doubt that (-1)^i, where i is an iterator, is useful in
many, many cases. However, you would need for pow(int, int) to
return a complex number all the time, if you want to handle that
use case, not just when i<0. That will make a lot of other code a
lot more complicated. It is much simpler to convert -1 to complex
and then call pow(complex, int) and return a complex number. That
means that whether i=1 or i=2, the result is complex. That will
make your life a lot less complicated, particularly if you pass
that result to other functions.
More information about the Digitalmars-d
mailing list