I just realized now that the result from JEP is not actually a wrong result, it's just not the "simplest" one. For rational exponents, there can be multiple results. For example 4^(1/2) can be both 2 or -2. I agree that it would be nicer to get the real result rather than the complex one, so we'll try to incorporate this in future versions.
Is there perhaps a definition of "power" that uniquely associates a result with a specific base-exponent combination?
It looks like it would not be straightforward to make JEP return -2 rather than the complex result for (-8)^(1/3). If anybody knows of a simple solution on how to do this, let me know.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Unit test displaying the problem
Logged In: YES
user_id=187315
I'll have to look into this one. Thanks for the report!
Logged In: YES
user_id=187315
Originator: NO
It looks like the bug might be in org/nfunk/jep/type/Complex.java in the power function. I'm looking into this and hope to have a fix available soon.
Logged In: YES
user_id=187315
Originator: NO
I just realized now that the result from JEP is not actually a wrong result, it's just not the "simplest" one. For rational exponents, there can be multiple results. For example 4^(1/2) can be both 2 or -2. I agree that it would be nicer to get the real result rather than the complex one, so we'll try to incorporate this in future versions.
Is there perhaps a definition of "power" that uniquely associates a result with a specific base-exponent combination?
It looks like it would not be straightforward to make JEP return -2 rather than the complex result for (-8)^(1/3). If anybody knows of a simple solution on how to do this, let me know.