Bug #10306
closedBigNum error
Description
Some calculations are wrong when dealing with large bignums.
For example, try 1000000000 ** 99, the result is obviously not right.
Updated by sawa (Tsuyoshi Sawada) over 9 years ago
Cannot be reproduced on ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux]. I get the correct result:
1000000000 ** 99
# => 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
(1000000000 ** 99).to_s.count("0")
# => 891
1000000000.to_s.count("0") * 99
# => 891
Updated by t-nissie (Takeshi Nishimatsu) over 9 years ago
On Darwin (Mac OS X), I made miniruby with /usr/bin/cc and /usr/local/bin/gcc (gcc-4.8.2 installed by myself).
I got the same correct results with both minirubys:
$ /usr/bin/cc --version
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
$ /usr/local/bin/gcc --version
gcc (GCC) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ ./miniruby -v -e 'p (1000000000 ** 99).to_s.count("0")'
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin13.0]
891
Updated by nobu (Nobuyoshi Nakada) over 9 years ago
- Status changed from Open to Feedback
- Priority changed from Normal to 3
What result did you get?
The word "obvious" is not obvious.
Updated by Nax (Max Bacoux) over 9 years ago
My bad, copy-pasted the wrong line from irb during some test, i'm sorry.
Anyways, the problem arise when you do 1000000 ** 99999
1000000 ** 99999
=> 99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999995084223284714385362871051527436447723160446818498959988211353135636965138570438599063576816273102709478518085193131290467462906404806976488907525699971444534907380395005541372243400335999766976532174448197
(Hundred more lines ...)
33337324537194556352749757443571869265512805361814821187272469723152678229173033451212668533651537920
It's obviously not the right result. As BigInt is supposed to have absolute precision, there is probably an issue here.
Again, sorry for mis-reporting the issue in the original bug report. I hope it's correct now.
Updated by akr (Akira Tanaka) over 9 years ago
Would you try latest trunk or 2.1 branch?
I fixed a bug recently. [Bug #10465]
Note that using GMP should also fix the problem.
Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago
- Status changed from Feedback to Closed