really small values

mensanator at mensanator at
Thu Jul 19 07:11:54 CEST 2007

On Jul 17, 4:13?pm, "Dee Asbury" <deeasb... at> wrote:
> In multiplying a value of xe^-325 with ye^-4, Python is returning zero. How
> do I get it to give me back my tiny value?

Use the right tool for the right job.

>>> import gmpy
>>> help(gmpy.mpf)
Help on built-in function mpf in module gmpy:

    mpf(n): builds an mpf object with a numeric value n (n may be any
            Python number, or an mpz, mpq, or mpf object) and a
            precision (in bits) depending on the nature of n
    mpf(n,bits=0): as above, but with the specified number of bits (0
            means to use default precision, as above)
    mpf(s,bits=0,base=10): builds an mpf object from a string s made
up of
            digits in the given base, possibly with fraction-part
            period as a separator) and/or exponent-part (with exponent
            marker 'e' for base<=10, else '@'). If base=256, s must be
            a gmpy.mpf portable binary representation as built by the
            function gmpy.fbinary (and the .binary method of mpf
            The resulting mpf object is built with a default precision
            bits) if bits is 0 or absent, else with the specified
            of bits.

>>> a = gmpy.mpf('3e-325')
>>> a
>>> b = gmpy.mpf('2e-4')
>>> b
>>> a*b

> Thanks!
> Dee
> "The most exciting phrase to hear in science, the one that
> heralds new discoveries, is not 'Eureka!' but 'That's funny...'"
>        - Isaac Asimov

More information about the Python-list mailing list