BUG: `Real.toRational` hangs on `pow` function
Trying to use the Real to calculate an exponential using the latest stable version (0.10.1). When I create the type no problem. Its when the toRational is executed, whether directly or not, that it hangs.
Examples (all those in comments will hang):
//val r2 = Real(2).fpow(Real(3))
//val r2 = Real.e.fpow(Real(3))
//val r2 = Real(2).pow(3.0)
//val r2 = Real(2.0).pow(3.0)
//val r2 = Real(2).fpow(3)
val r2 = Real(2).pow(3)
val s = r2.toRational // hangs here
The power function seems to work only when the exponent is an integer. I tracked this down to the class:
case class Inexact(f: Int => SafeLong)
When the applyis invoked it enters the None (second) case. Then it execute f(p) and Inexact.apply is called again. The looping seems to start here.
This is a show stopper for me. Any way I can get around this?
@hmf Ouch! I'll investigate now. Thanks for reporting.
@non I have tried to search a little more and it seems to lead to Rational@90:
def limitToInt: Rational = limitTo(BigInt(Int.MaxValue))
I now wonder if this is not the same issue as #393
OK, I see what is happening. It is an easy bug to fix.
As a work-around you can break apart a rational number and apply the .pow and .nroot calls separately. I'll try to get a fix released ASAP.
Yeah, it's definitely related to a problem with .limitToInt. In the case we care about it is easy to fix -- I'll have to see if it fixes that bug too.
I'll try to get a release out with a fix for this ASAP.
Thank you very much.