On Wed, Sep 8, 2010 at 22:10, Michael Gilbert
<[email protected]> wrote:
> Here is an example:
>
> >>> 0.3/3.0 - 0.1
> -1.3877787807814457e-17
>
> >>> mpmath.mpf( '0.3' )/mpmath.mpf( '3.0' ) - mpmath.mpf( '0.1' )
> mpf('-1.3877787807814457e-17')
>
> >>> decimal.Decimal( '0.3' )/decimal.Decimal( '3.0' ) - decimal.Decimal (
> '0.1' )
> Decimal("0.0")
>
> Decimal solves the problem; whereas mpmath doesn't.
you can change mpmath precision up to an arbitrary high value:
In [4]: mpmath.mp.prec = 100
In [5]: mpmath.mpf( '0.3' )/mpmath.mpf( '3.0' ) - mpmath.mpf( '0.1' )
Out[5]: mpf('0.0')
Regards.
--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi
_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion