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) almost 14 years ago. Updated about 12 years ago.

Status:
Closed
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 #1

Updated by Eregon (Benoit Daloze) almost 14 years ago

=begin
"And IntegerInteger should always return an Integer (Infinity is a Float)"
=> I meant Integer
(positive Integer) of course
=end

Actions #2

Updated by mame (Yusuke Endoh) almost 14 years ago

  • Target version changed from 1.9.2 to 2.0.0

=begin
Hi,

I agree that it is not good behavior, but it is definitely intended
and traditional behavior. Not a bug.

1.9.2 should not be changed. Let's discuss towards 1.9.3.
I move to 1.9.x feature request.

--
Yusuke Endoh
=end

Actions #3

Updated by Eregon (Benoit Daloze) almost 14 years ago

=begin
On 11 June 2010 15:58, Yusuke Endoh wrote:
| I agree that it is not good behavior, but it is definitely intended
| and traditional behavior.  Not a bug.

For a mathematician, and even if he takes care of computing
limitations, he would think it is a bug I believe ;)
Python, by example, does not complain (and it works) for this.
But yes, this behavior is common in many languages I suppose, but as
we have Bignum built-in, it seems logical Integer*(Integer>0) returns
an Integer, whatever the size is, at least until it becomes too bad
for the memory.

| 1.9.2 should not be changed.  Let's discuss towards 1.9.3.
| I move to 1.9.x feature request.

Sure, I was hesitating for the target. As I think it is important
because it is basic maths, I did choose 1.9.2.

| Yusuke Endoh

B.D

=end

Updated by nahi (Hiroshi Nakamura) about 12 years ago

  • Description updated (diff)
  • Assignee set to mrkn (Kenta Murata)

mrkn, please handle this.

Actions #5

Updated by nobu (Nobuyoshi Nakada) about 12 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r35081.
Benoit, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0