From: "byroot (Jean Boussier) via ruby-core" Date: 2024-10-24T07:40:06+00:00 Subject: [ruby-core:119603] [Ruby master Feature#20811] `warning: in a**b, b may be too big` is really helpful? 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/