Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve ** passed big integer failure #3037

Closed
kares opened this issue Jun 11, 2015 · 2 comments
Closed

improve ** passed big integer failure #3037

kares opened this issue Jun 11, 2015 · 2 comments

Comments

@kares
Copy link
Member

kares commented Jun 11, 2015

currently blows up as: java.lang.ArithmeticException: Negative exponent

pow_failure.rb:3: warning: in a**b, b may be too big
BigInteger.java:1395:in `pow': java.lang.ArithmeticException: Negative exponent
    from RubyBignum.java:608:in `op_pow19'
    from RubyBignum.java:573:in `op_pow'
    from Numeric.java:500:in `int_pow'
    from RubyFixnum.java:815:in `powerFixnum19'
    from RubyFixnum.java:765:in `op_pow_19'
    from RubyFixnum.java:727:in `op_pow'
    from RubyFixnum$INVOKER$i$1$0$op_pow.gen:-1:in `call'
    from CachingCallSite.java:161:in `call'
    from pow_failure.rb:-1:in `invokeOther10:**'
    from pow_failure.rb:3:in `RUBY$method$knuth$0'
    from CompiledIRMethod.java:161:in `call'
    from DynamicMethod.java:221:in `call'
    from CachingCallSite.java:225:in `call'
    from pow_failure.rb:-1:in `invokeOther8:knuth'
    from pow_failure.rb:7:in `RUBY$block$knuth$2'
    from CompiledIRBlockBody.java:70:in `commonYieldPath'
    from IRBlockBody.java:66:in `yieldSpecific'
    from Block.java:116:in `yieldSpecific'
    from RubyFixnum.java:299:in `times'
    from RubyFixnum$INVOKER$i$0$0$times.gen:-1:in `call'
    from CachingCallSite.java:139:in `callBlock'
    from CachingCallSite.java:145:in `call'
    from pow_failure.rb:-1:in `invokeOther13:times'
    from pow_failure.rb:6:in `RUBY$method$knuth$0'
    from CompiledIRMethod.java:161:in `call'
    from DynamicMethod.java:221:in `call'
    from CachingCallSite.java:225:in `call'
    from pow_failure.rb:-1:in `invokeOther8:knuth'
    from pow_failure.rb:7:in `RUBY$block$knuth$2'
    from CompiledIRBlockBody.java:70:in `commonYieldPath'
    from IRBlockBody.java:66:in `yieldSpecific'
    from Block.java:116:in `yieldSpecific'
    from RubyFixnum.java:299:in `times'
    from RubyFixnum$INVOKER$i$0$0$times.gen:-1:in `call'
    from CachingCallSite.java:139:in `callBlock'
    from CachingCallSite.java:145:in `call'
    from pow_failure.rb:-1:in `invokeOther13:times'
    from pow_failure.rb:6:in `RUBY$method$knuth$0'
    from CompiledIRMethod.java:161:in `call'
    from DynamicMethod.java:221:in `call'
    from CachingCallSite.java:225:in `call'
    from pow_failure.rb:-1:in `invokeOther8:knuth'
    from pow_failure.rb:7:in `RUBY$block$knuth$2'
    from CompiledIRBlockBody.java:70:in `commonYieldPath'
    from IRBlockBody.java:66:in `yieldSpecific'
    from Block.java:116:in `yieldSpecific'
    from RubyFixnum.java:299:in `times'
    from RubyFixnum$INVOKER$i$0$0$times.gen:-1:in `call'
    from CachingCallSite.java:303:in `cacheAndCall'
    from CachingCallSite.java:141:in `callBlock'
    from CachingCallSite.java:145:in `call'
    from pow_failure.rb:-1:in `invokeOther13:times'
    from pow_failure.rb:6:in `RUBY$method$knuth$0'
    from CompiledIRMethod.java:161:in `call'
    from DynamicMethod.java:221:in `call'
    from CachingCallSite.java:353:in `cacheAndCall'
    from CachingCallSite.java:227:in `call'
    from pow_failure.rb:-1:in `invokeOther17:knuth'
    from pow_failure.rb:13:in `RUBY$script'
    from MethodHandle.java:599:in `invokeWithArguments'
    from Compiler.java:111:in `load'
    from Ruby.java:835:in `runScript'
    from Ruby.java:824:in `runScript'
    from Ruby.java:754:in `runNormally'
    from Ruby.java:575:in `runFromMain'
    from Main.java:401:in `doRunFromMain'
    from Main.java:296:in `internalRun'
    from Main.java:225:in `run'
    from Main.java:197:in `main'

script (taken from http://stackoverflow.com/questions/30765980/java-lang-arithmeticexception-negative-exponent-in-jruby) :

def knuth(a, n, b)
   if n ==1
      r = a**b
   else
      r = 1
      b.times do
         r = knuth a, n-1, r
      end
   end
   return r
end
k = knuth 3, 4, 5
puts k
puts k.size
@robinbortlik
Copy link

I tried to fix it, but I was not successful. So at least, I'm attaching the failing spec

it "returns Infinity for '3**7625597484987'" do
   (3**7625597484987).should == (1.0/0)
end

MRI result

irb(main):001:0> 3**7625597484987
(irb):1: warning: in a**b, b may be too big
=> Infinity

@kares
Copy link
Member Author

kares commented Jul 9, 2015

Thanks Robin, this actually slipped into 1.7.21 already with d828f5f and 0f63239

@kares kares closed this as completed Jul 9, 2015
@kares kares modified the milestones: JRuby 1.7.22, JRuby 1.7.21 Jul 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants