[Numpy-discussion] IEEE 754-2008 decimal floating point support
Sandro Tosi
morph@debian....
Wed Sep 8 15:20:30 CDT 2010
On Wed, Sep 8, 2010 at 22:10, Michael Gilbert
<michael.s.gilbert@gmail.com> 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
More information about the NumPy-Discussion
mailing list