danvim / ProcalParsing

0 stars 2 forks source link

Cannot power negative #5

Closed danvim closed 7 years ago

danvim commented 7 years ago

What happened

(-1)^(-1) returns an error

java.lang.ArithmeticException: Cannot power negative -1.000000000000000
        at org.nevec.rjm.BigDecimalMath.pow(BigDecimalMath.java:767)
        at fx50.nodes.PowerNode.evaluate(PowerNode.java:20)
        at fx50.nodes.StatementNode.evaluate(StatementNode.java:29)
        at fx50.Main$Run.run(Main.java:118)
        at fx50.Main$Run.run(Main.java:127)
        at fx50.Main$Run.run(Main.java:127)
        at fx50.Main.main(Main.java:29)
Error: Cannot power negative -1.000000000000000

What should have happened

(-1)^(-1) should return -1


What might be the problem

The rjm library.

mcreng commented 7 years ago

should be partially fixed in commit https://github.com/danvim/ProcalParsing/commit/06b39cc44b7539c3fbf789406e7730aa139e5d9c. The remaining part is (negative number)^(float), in theory all of them should involve complex numbers but for some float (those which are rational with odd denominator) would have a real root, so we will do it the way fx-50FH does it, that we just returns the real root and neglecting the other complex roots.

mcreng commented 7 years ago

Should be fixed completely in commit https://github.com/danvim/ProcalParsing/commit/b7f031da9d1c2ba29e175d80812d4e8cf672c850 with the method of dealing float power as above.