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

jmh530 john.michael.hall at gmail.com
Mon Dec 16 13:20:58 UTC 2019


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.


More information about the Digitalmars-d mailing list