Project

General

Profile

Actions

Feature #3429

closed

Integer#**(large) warns "in a**b, b may be too big" and return Infinity

Added by Eregon (Benoit Daloze) about 12 years ago. Updated over 10 years ago.

Status:
Closed
Priority:
Normal
Target version:
[ruby-core:30735]

Description

=begin
Hi,

Trying to do
intsome_large_number can result in
"warning: in a
b, b may be too big"
#=> Infinity
By example,
2**7830457

It is not good behavior, as we can make a workaround and it works perfectly:

7830457 = 2 * 37 * 105817 - 1

n = (((2 ** 105817) ** 37) ** 2) / 2 # => ...8739992577 which is the good number

I think it is not consistent to return Infinity when a correct answer can be given.
And Integer**Integer should always return an Integer (Infinity is a Float)

Also, while doing some tests about this I noticed that "bignum == Float::INFINITY" or "bignum.infinite?" hangs, while it should not, as it is always false.

See the script attached for some details and a (nonsense) implementation Integer#int_pow method which show it is possible to get better results.
=end


Files

integer_pow.rb (1.23 KB) integer_pow.rb Eregon (Benoit Daloze), 06/11/2010 10:36 PM

Related issues 1 (0 open1 closed)

Related to Backport193 - Backport #6605: Rational#round causes irb to crash when given a reasonably absurd precision valueClosednaruse (Yui NARUSE)06/19/2012Actions
Actions

Also available in: Atom PDF