really small values

mensanator at aol.com mensanator at aol.com
Thu Jul 19 01:11:54 EDT 2007


On Jul 17, 4:13?pm, "Dee Asbury" <deeasb... at msn.com> 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(...)
    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
default
            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
(with
            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
objects).
            The resulting mpf object is built with a default precision
(in
            bits) if bits is 0 or absent, else with the specified
number
            of bits.

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


>
> 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