Our professor said that you can\'t calculate ab if a<0 using pow()
because pow()
uses natural logarithms to calculate it (ab
pow
does work for negative numbers. It just doesn't work when the base is negative and the exponent is not an integer.
A number in the form ax/y actually involves the y-th root of x. For instance, when you try to calculate a1/2 you are actually looking for the square root of a.
So what happens if you have a negative base and a non-integer exponent? You get a y-th root of a negative number, which yields is a complex non-real number. pow()
does not work with complex numbers, so it will probably return NaN.