Rational powers with negative base

Issue #984 new
Noora Nieminen created an issue

I tried to calculate (-20)^(1/7) but the calculation yields NaN as if it was not defined. With any other odd n (except those being 7 or 49), the computation of (-20)^(1/n) is successful. This same issue occurs with any negative base for powers 1/7 and 1/49, but no other power of form 1/n with an odd n.

Is this somehow due to the algorithm that the power function ^ or what might cause this unexpected behavior?

Comments (2)

  1. Pol Welter

    Raising a negative number to a fractional number is poorly defined. A real solution exists if a) the exponent is rational and b) the reduced denominator is odd.

    I have implemented this in hmath.cpp:1251. That's the code that needs to be debugged.

  2. Log in to comment