Integer#**(large) warns "in a**b, b may be too big" and return Infinity
Trying to do
int*some_large_number can result in
"warning: in ab, b may be too big"
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.
#2 Updated by mame (Yusuke Endoh) almost 7 years ago
- Target version changed from 1.9.2 to 2.0.0
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 email@example.com
#3 Updated by Eregon (Benoit Daloze) almost 7 years ago
On 11 June 2010 15:58, Yusuke Endoh firstname.lastname@example.org 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 email@example.com
#5 Updated by nobu (Nobuyoshi Nakada) about 5 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100