Project

General

Profile

Actions

Feature #20811

closed

`warning: in a**b, b may be too big` is really helpful?

Added by mame (Yusuke Endoh) about 1 month ago. Updated 16 days ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:119602]

Description

I tried to calculate the largest prime number recently discovered. However, it did not work. I was a bit disappointed.

$ ruby -e 'p 2**136279841-1'
-e:1: warning: in a**b, b may be too big
Infinity

I know this is not a realistic case, but I checked my past chat logs and found a record of the same thing six years ago and the same disappointment.

$ ruby -e 'p 2**77232917-1'
-e:1: warning: in a**b, b may be too big
Infinity

So I would like to ask, has anyone experienced that this behavior has actually been helpful?

I think that this limit is to prevent a program from unintentionally spending too much time and memory trying to compute a power that is too large. However, is it helpful to return Infinity in such a situation? I think raising an exception would be safer, if this limit is really needed.

Also, is this limit appropriate? On my machine, 2 ** 32537661 is calculated normally and 2 ** 32537662 returns Infinity. This calculation took about 100 ms and 400 kB. I think this is short enough for a single computation time. Incidentally, 2 ** 32537661 in decimal notation is 9,794,814 digits, which may be too loose a limit considering the display.

Note that this limit only applies when calculating the power directly. (2 ** 32537661) * 2 returns an Integer, not Infinity. Even 1 << 32537662 gives an Integer.

From the above, I suspect that this limit is not particularly useful and only spoils the fun of mathematics. What do you think?

Actions

Also available in: Atom PDF

Like2
Like0Like0Like0Like0Like0