mpz_out_str seg fault with large number = bug?
sisyphus1 at optusnet.com.au
Thu Aug 4 03:09:37 CEST 2005
----- Original Message -----
From: <viny at adinet.com.uy>
To: "Torbjorn Granlund" <tege at swox.com>
Cc: <gmp-discuss at swox.com>
Sent: Thursday, August 04, 2005 10:56 AM
Subject: Re: mpz_out_str seg fault with large number = bug?
> > Is there any documentation about the admisible range of those
> >Please see http://swox.com/gmp/#FAQ.
> After checking the FAQ, I hit the following sentence in the future
> "Support at the mpn and mpz levels for operands of up to 2^56 bits (on
> machines). Current limits are: on 32-bit machines, 2^31 bits; on 64-bit
> 2^37 bits".
I think he meant for you to read the following from the FAQ:
Q: I get a Segfault/Bus error in a program that uses GMP to calculate
numbers with several hundred thousand digits. Why?
A: GMP allocates most temporaries on the stack, and some machines give user
programs very little stack space by default. See setrlimit(2) for
information on how to increase the stack allocation. You can also change it
from the shell (using ulimit or limit depending on the shell). You can also
configure with --disable-alloca to instead allocate temporaries using
malloc, but that will make the library run somewhat slower.
Factorial 10^6 is a fairly large number and requires a lot of stack space
when being converted to a base 10 number.
As another alternative solution to that presented above, if you have
mpz_out_str() output a base 2, 4, 8, 16, or 32 number (instead of base 10),
then that will probably work fine - because such conversions require very
little stack space.
More information about the gmp-discuss