calculating exp[-300]

Karl Hasselström kha at
Tue Apr 26 18:00:43 CEST 2005

On 2005-04-26 10:17:47 -0500, Nathan Moore wrote:

> I'm working on a monte-carlo simulation which requires the
> calculation of probability for rather high energy levels, Boltzmann
> probability defined, exp(-u/T). The quantity u/T is occasionally
> very large, and in some cases always large. I'd like to use GMP
> rational numbers (mpq_t) to represent the probability and partition
> function of the system.

I think this is a wrong turn. mpq numbers are fractions, and
operations on them always give exact results (expending whatever
effort is necessary to do so). Your numbers aren't representable as
fractions anyway, so you don't get exact answers no matter what you
do, so you might as well use mpf (floating-point) numbers instead.
That'll reduce your execution time quite a lot, I think.

Karl Hasselström, kha at

More information about the gmp-discuss mailing list