ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:119602] [Ruby master Feature#20811] `warning: in a**b, b may be too big` is really helpful?
@ 2024-10-24  7:25 mame (Yusuke Endoh) via ruby-core
  2024-10-24  7:40 ` [ruby-core:119603] " byroot (Jean Boussier) via ruby-core
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2024-10-24  7:25 UTC (permalink / raw)
  To: ruby-core; +Cc: mame (Yusuke Endoh)

Issue #20811 has been reported by mame (Yusuke Endoh).

----------------------------------------
Feature #20811: `warning: in a**b, b may be too big` is really helpful?
https://bugs.ruby-lang.org/issues/20811

* Author: mame (Yusuke Endoh)
* Status: Open
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:119603] [Ruby master Feature#20811] `warning: in a**b, b may be too big` is really helpful?
  2024-10-24  7:25 [ruby-core:119602] [Ruby master Feature#20811] `warning: in a**b, b may be too big` is really helpful? mame (Yusuke Endoh) via ruby-core
@ 2024-10-24  7:40 ` byroot (Jean Boussier) via ruby-core
  2024-10-24 10:12 ` [ruby-core:119604] " Eregon (Benoit Daloze) via ruby-core
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: byroot (Jean Boussier) via ruby-core @ 2024-10-24  7:40 UTC (permalink / raw)
  To: ruby-core; +Cc: byroot (Jean Boussier)

Issue #20811 has been updated by byroot (Jean Boussier).


Agreed. Either Ruby can't do it and should raise some sort of error, or just do it even if it uses gigabytes of memory.

That warning isn't helping anyone, and returning `Infinity` is a huge gotcha and totally unexpected.

----------------------------------------
Feature #20811: `warning: in a**b, b may be too big` is really helpful?
https://bugs.ruby-lang.org/issues/20811#change-110225

* Author: mame (Yusuke Endoh)
* Status: Open
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:119604] [Ruby master Feature#20811] `warning: in a**b, b may be too big` is really helpful?
  2024-10-24  7:25 [ruby-core:119602] [Ruby master Feature#20811] `warning: in a**b, b may be too big` is really helpful? mame (Yusuke Endoh) via ruby-core
  2024-10-24  7:40 ` [ruby-core:119603] " byroot (Jean Boussier) via ruby-core
@ 2024-10-24 10:12 ` Eregon (Benoit Daloze) via ruby-core
  2024-11-07 10:17 ` [ruby-core:119798] " mame (Yusuke Endoh) via ruby-core
  2024-11-08  9:25 ` [ruby-core:119838] " mame (Yusuke Endoh) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2024-10-24 10:12 UTC (permalink / raw)
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

Issue #20811 has been updated by Eregon (Benoit Daloze).


Agreed it should just compute it.
It should still be interruptible by Ctrl+C though, but it probably already is.

----------------------------------------
Feature #20811: `warning: in a**b, b may be too big` is really helpful?
https://bugs.ruby-lang.org/issues/20811#change-110226

* Author: mame (Yusuke Endoh)
* Status: Open
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:119798] [Ruby master Feature#20811] `warning: in a**b, b may be too big` is really helpful?
  2024-10-24  7:25 [ruby-core:119602] [Ruby master Feature#20811] `warning: in a**b, b may be too big` is really helpful? mame (Yusuke Endoh) via ruby-core
  2024-10-24  7:40 ` [ruby-core:119603] " byroot (Jean Boussier) via ruby-core
  2024-10-24 10:12 ` [ruby-core:119604] " Eregon (Benoit Daloze) via ruby-core
@ 2024-11-07 10:17 ` mame (Yusuke Endoh) via ruby-core
  2024-11-08  9:25 ` [ruby-core:119838] " mame (Yusuke Endoh) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2024-11-07 10:17 UTC (permalink / raw)
  To: ruby-core; +Cc: mame (Yusuke Endoh)

Issue #20811 has been updated by mame (Yusuke Endoh).


Matz said "let's calculate". I will create a PR

----------------------------------------
Feature #20811: `warning: in a**b, b may be too big` is really helpful?
https://bugs.ruby-lang.org/issues/20811#change-110483

* Author: mame (Yusuke Endoh)
* Status: Open
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:119838] [Ruby master Feature#20811] `warning: in a**b, b may be too big` is really helpful?
  2024-10-24  7:25 [ruby-core:119602] [Ruby master Feature#20811] `warning: in a**b, b may be too big` is really helpful? mame (Yusuke Endoh) via ruby-core
                   ` (2 preceding siblings ...)
  2024-11-07 10:17 ` [ruby-core:119798] " mame (Yusuke Endoh) via ruby-core
@ 2024-11-08  9:25 ` mame (Yusuke Endoh) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2024-11-08  9:25 UTC (permalink / raw)
  To: ruby-core; +Cc: mame (Yusuke Endoh)

Issue #20811 has been updated by mame (Yusuke Endoh).


I have created https://github.com/ruby/ruby/pull/12033

This patch changes the behavior of `Integer#**` and `Rational#**`. If the generated bignum is not likely to exceed an estimated 16 GB, it will be calculated straightforwardly. If it is likely to exceed 16 GB, an ArgumentError is raised.

`Complex#**` also prints a warning "in a**b, b may be too big", but I found a bit more subtle issue, so I will create a separate ticket.

----------------------------------------
Feature #20811: `warning: in a**b, b may be too big` is really helpful?
https://bugs.ruby-lang.org/issues/20811#change-110528

* Author: mame (Yusuke Endoh)
* Status: Open
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-11-08  9:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-24  7:25 [ruby-core:119602] [Ruby master Feature#20811] `warning: in a**b, b may be too big` is really helpful? mame (Yusuke Endoh) via ruby-core
2024-10-24  7:40 ` [ruby-core:119603] " byroot (Jean Boussier) via ruby-core
2024-10-24 10:12 ` [ruby-core:119604] " Eregon (Benoit Daloze) via ruby-core
2024-11-07 10:17 ` [ruby-core:119798] " mame (Yusuke Endoh) via ruby-core
2024-11-08  9:25 ` [ruby-core:119838] " mame (Yusuke Endoh) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).