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

M.M. matus at
Mon Dec 16 13:53:06 UTC 2019

On Monday, 16 December 2019 at 13:20:58 UTC, jmh530 wrote:
> On Monday, 16 December 2019 at 12:39:11 UTC, M.M. wrote:
>> [snip]
>> As such, (-1)^^i is _extremely_ useful and common, and 
>> changing how (common) math works in a programming language is 
>> asking for troubles.
> I'm a little confused by this thread...
> 1) the bug report is about a function taking an int and an int. 
> Just focusing on the math, the result of the function with a 
> negative exponent would be a float. So, it makes perfect sense 
> for the function to prevent this when dealing with ints only. 
> Just cast part of it to float and you get the right result.
> 2) I'm so confused by why everyone is bringing up (-1)^^i.
> a) i normally represents sqrt(-1) in math, so that's a complex 
> number...the overload deals with ints. You should be concerned 
> by an overload for complex numbers.
> b) This conversation would make a little more sense is if we 
> are considering i as a member of the set (0, 1, 2, 3, ...). In 
> which case, the value is still a complex number most of the 
> time. IMO, people concerned with this case should cast -1 to 
> complex and then call pow.
> 3) In math, we have different types of numbers: natural 
> numbers, rational numbers, real numbers. Just because a formula 
> has a defined result for every value of complex numbers, 
> doesn't mean that is the case for the other types of numbers. 
> Computer science types, like int and float, have some analog in 
> math numbers, but they aren't the same thing. I think you'll 
> get confused when trying to think they are the exact same thing.

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.

More information about the Digitalmars-d mailing list