Menu

#7 Power function and "third root"

open
None
5
2006-12-05
2006-11-02
No

Parsing and evaluating the expression "(-8)^(1/3.0)
with JEP produces a complex result, while I'm expecting
-2.0.

See example in the attached unit test.

Discussion

  • Jan Mattsson

    Jan Mattsson - 2006-11-02

    Unit test displaying the problem

     
  • Nathan Funk

    Nathan Funk - 2006-11-03
    • milestone: 445840 --> 606446
    • priority: 5 --> 9
    • assigned_to: nobody --> nathanfunk
     
  • Nathan Funk

    Nathan Funk - 2006-11-03

    Logged In: YES
    user_id=187315

    I'll have to look into this one. Thanks for the report!

     
  • Nathan Funk

    Nathan Funk - 2006-12-01

    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.

     
  • Nathan Funk

    Nathan Funk - 2006-12-05

    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.

     
  • Nathan Funk

    Nathan Funk - 2006-12-05
    • milestone: 606446 -->
    • priority: 9 --> 5
     

Log in to post a comment.

MongoDB Logo MongoDB