[Numpy-discussion] IEEE 754-2008 decimal floating point support
Michael Gilbert
michael.s.gilbert@gmail....
Wed Sep 8 15:10:20 CDT 2010
On Wed, 8 Sep 2010 15:04:17 -0500, Robert Kern wrote:
> On Wed, Sep 8, 2010 at 14:44, Michael Gilbert
> <michael.s.gilbert@gmail.com> wrote:
> > On Wed, Sep 8, 2010 at 12:23 PM, Charles R Harris wrote:
> >>
> >>
> >> On Wed, Sep 8, 2010 at 9:46 AM, Michael Gilbert
> >> <michael.s.gilbert@gmail.com> wrote:
> >>>
> >>> On Wed, 8 Sep 2010 09:43:56 -0600, Charles R Harris wrote:
> >>> > On Wed, Sep 8, 2010 at 9:26 AM, Michael Gilbert
> >>> > <michael.s.gilbert@gmail.com
> >>> > > wrote:
> >>> >
> >>> > > Hi,
> >>> > >
> >>> > > Are there any plans to add support for decimal floating point
> >>> > > arithmetic, as defined in the 2008 revision of the IEEE 754 standard
> >>> > > [0], in numpy?
> >>> > >
> >>> > >
> >>> > Not at the moment. There is currently no hardware or C support and
> >>> > adding
> >>> > new types to numpy isn't trivial. You can get some limited Decimal
> >>> > functionality by using python classes and object arrays, for instance
> >>> > the
> >>> > Decimal class in the python decimal module, but the performance isn't
> >>> > great.
> >>> >
> >>> > What is your particular interest in decimal support?
> >>>
> >>> Primarily avoiding catastrophic cancellation when subtracting
> >>> large values. I was planning to use the decimal class, but was
> >>> curious whether support for the IEEE standard was coming any time soon.
> >>>
> >>
> >> If you just need more precision, mpmath has better performance than the
> >> Decimal class. Also, it might be possible to avoid the loss of precision by
> >> changing the computation, but I don't know the details of what you are
> >> doing.
> >
> > Just wanted to say that numpy object arrays + decimal solved all of my
> > problems, which were all caused by the disconnect between decimal and
> > binary representation of floating point numbers.
>
> Are you sure? Unless if I'm failing to think through this properly,
> catastrophic cancellation for large numbers is an intrinsic property
> of fixed-precision floating point regardless of the base. decimal and
> mpmath both help with that problem because they have arbitrary
> precision.
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.
Mike
More information about the NumPy-Discussion
mailing list