Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-12-07 14:33:08


>From the new Test Library review, Gennady just proposed to start a
discussion about comparing floating point numbers in its own thread.
Although the subject is not directly related to any particular library, it
is, IMO, related to the future development of numerical oriented boost
libraries.
If the list moderators agree, I'll start this thread here.

From: rogeeff <rogeeff_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, December 07, 2001 4:16 PM
Subject: [boost] Re: Formal review: New Boost.Test Library

> > > > "The rounding error for a floating-point value should not exceed
> > > one half of
> > > > the std::numeric_limits<T>::epsilon(). "
> > > >
> > > > Actually, the error is for the "operation", not the "value".
> > > > Besides, and more importantly, this rule holds only with
> respect to
> > > > *arithmetic* operations: + - * /
> > > > It doesn't hold, for instance, if you call 'sqrt()'.
> > >
> > > If you write float f = 0.1;
> > > (f - real 0.1) could be different from 0, but should not exceed
> one
> > > half of the std::numeric_limits<T>::epsilon()
> >
> > Right, because the source of errors are (1) the promotion and (2)
> the
> > operation -.
> > Errors are only bounded to operations, including conversions, not
> values.
> >
> > > More correct statement vould be: for values and arithmetic
> operation.
> > >
> > IMO, "for (standard conformant) conversions and arithmetic
> operations".
>
> Sorry confusing example. Another one:
> double d = 0.1;
>
> You do not have a promotion here, but d still do not equal to 0.1
> precisely. Reason is that 0.1 is 0.0001100110011... in binary format.
>
Actually, you have a conversion from the 'decimal representation' 0.1 to its
binary format, so again there is
a conversion as the source of the error.
I know this might be subtle, and that most users might not realize the
implicit conversion used by the compiler when parsing '0.1';
but since we are talking about an informative but also *formative* document,
I think it could be necessary to be more strict in the terminology and
concepts even if it involves a larger document.

> I propose to separate discutssion about floating-point comparison in
> separate thread. I have several issues/questions that I would like to
> discuss.
>

What exactly would you like to discuss?

Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk