[bigint] [BUG?] Segfault when trying to calculate very large factorials
Max Maass <0maass at informatik.uni-hamburg.de>
Wed Jun 5 05:36:27 PDT 2013
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi there,
I am experimenting with the library for calculating very large
binomial coefficients, which requires very large factorials.
Since there is no gamma function for the BigInteger Libraries, I opted
for the primitive approach:
- --
BigUnsigned factorial(BigUnsigned number) {
BigUnsigned temp;
if(number <= 1) return 1;
temp = number * factorial(number - 1);
return temp;
}
- --
This works fine up to an input value of up to and including 58197,
afterwards it throws a segfault.
Interestingly enough, if I wrap the call inside a for loop like:
- --
for (BigUnsigned n = 58197; n <= 217000; n++) {
cout << factorial(n) << endl;
}
- --
it works just fine and keeps working above the magic number of 58197.
But if I change the BigUnsigned n = 58197 to 58200, it will instantly
segfault.
I am compiling using "g++ filename.cpp Big*.o -o filename" inside the
directory where all the libraries are (and after running make once). I
am getting the following messages on compilation:
- --
In file included from BigIntegerLibrary.hh:4:0,
from filename.cpp:2:
BigUnsigned.hh:23:2: warning: access declarations are deprecated in
favour of using-declarations; suggestion: add the ?using? keyword
[-Wdeprecated]
BigUnsigned.hh:87:2: warning: access declarations are deprecated in
favour of using-declarations; suggestion: add the ?using? keyword
[-Wdeprecated]
BigUnsigned.hh:88:2: warning: access declarations are deprecated in
favour of using-declarations; suggestion: add the ?using? keyword
[-Wdeprecated]
In file included from BigIntegerLibrary.hh:7:0,
from filename.cpp:2:
BigUnsignedInABase.hh:103:2: warning: access declarations are
deprecated in favour of using-declarations; suggestion: add the
?using? keyword [-Wdeprecated]
BigUnsignedInABase.hh:104:2: warning: access declarations are
deprecated in favour of using-declarations; suggestion: add the
?using? keyword [-Wdeprecated]
- --
And yes, my factorial algorithm is damn slow, but that is not the
point here ;-).
Please let me know if you need to know anything else.
Sincerely,
Max
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQIbBAEBAgAGBQJRrzDCAAoJEBafliQ0CIJet04P+IqROzcpZQfDa010qlqMWzHY
JsYMQpu2acuyVjz0l3xWTmym5DyEVY6JeiBqwnQh84/hfaK36larbZDyPx4lWR2d
dVJT8DUf/KpFWpVKMPfe+nbAH/Cu7YJo4edgvSqfMPa3pg7ErqQg6CG6AVqRye4j
O5zQyHwqRI46MwJyZ88nFlPJBkv89d0RaCIWnqRXYweUj/+3F8OqFn+ZB35hys8d
qmbjovERN0UqWyiQ1ta74O9i76IN5+L7MiWU/5mtSeZhBrf6CrBu+1KD3mL9cxhU
zDwlGHcal2vJf+AGMkyTUu6O2Xl27TMOX7c4lmRMQrj9vwc/AyE7ZiIZbl6iGO6P
QSeWR8G452nSbHKcPtVxhbNdsGDq2Ht1EQ+xXsPaoGWt3GbH8kNHwOT50ZQlI+bS
FW/BKlyOp98vS2P9PlpdHRGI2NSClCbXjgZcNHwtrv4zpaU5AAPLTxx5cEc6og0k
NNepzOo6uYrAAzP7Az0aWLoZzLIP8jsNoCLpW9aVVWfo9eZIvhJZhGIL1dSILQb3
B09JsWwrhB2hT2CSqSuUlc9BNgkOIjLbYuxNsIj/8knb0QdqvaoEczkmvVVjeqUQ
CbnvwLnOxKyk9QLO9lwKY82h+Ux6E4k4cU/62SpXwyits3Enx763wiR9wLKg0E2x
OFAAwxVeYhtnk1ddlNg=
=kxOQ
-----END PGP SIGNATURE-----
More information about the bigint
mailing list