Boost logo

Boost :

From: Kevlin Henney (kevlin_at_[hidden])
Date: 2000-04-25 05:29:53

In message <Pine.LNX.4.21.0004242309400.1390-100000_at_localhost.localdomai
n>, Kevin Atkinson <kevinatk_at_[hidden]> writes
>One well known problem with floating point numbers is that the normal
>comparisons won't work when the equality case is important. Therefore I
>propose a special adapter class be create called safe_double which will
>act almost exactly like double (which includes implicit conversion both
>ways) but will have "safe" comparison that will take into account
>rounding error.
>The only real issue, in my view, is what SMALL_VAL should be.
>What do you think? Do you think it would be a useful additional to the
>boost library. Naturally safe_float should also be created to compliment

A few thoughts on this:

* There seem to be two parameters of variation: one is precision (float,
double, long double) and the other is tolerance (ie what SMALL_VAL
should be). Template parameters sound like the answer. Although float
literals cannot be used directly as template parameters, there are some
ways round this.

* The prefix "safe_" does not really seem to convey the right message:
all comparisons are safe; the issue is whether or not they are sensible

* Is this concept really a property of a type? Or is it a property of
the comparison? I think it is the latter, in which case an algorithm
rather than a 'container' is the right way to go. Sure, it won't look as
pretty and transparent as the relational operators, but it will be a lot
more flexible and a lot more direct than creating a new type which
cannot be 100% substitutable.

  Kevlin Henney phone: +44 117 942 2990
  Curbralan Ltd mobile: +44 7801 073 508
  kevlin_at_[hidden] fax: +44 870 052 2289

Boost list run by bdawes at, gregod at, cpdaniel at, john at