Boost logo

Boost :

From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2007-02-14 08:39:07


Hi Dave,

> [snip]
> Fine. Now, we want to be able to compare more complicated
> mathematical objects, such as vectors and matrices.
>
> After some thought, we decided the responsibility for providing such
> functions is the responsibility of the mathematical object, not the
> unit test framework. That is to say, a function "relative difference
> between matrices" should be in Matrix.h, not some unit test thing.
>
For a high-level numerical package like one providing vectors and matrices,
you probably need something at a higher level than the Boost.Test
floating-point comparison tools.

For starters, the fp comparisons in Boost.Test are, precisely,
floating-point specific, while a high-level numerical package is probably
generic (unless your code is fixed to use 'float' or 'double'), so, if
usable comparisons are to be offered by the library, chances are you need
something generic that understand the underlying numeric type (that is a
policy or traits).

Buyt even if the number types are floating-point, the right comparison
strategy may depend on the domain. For instance, the Knuth approach works
well when the variables were subject to arithmetic operations (which have a
tight error bound), but if you use, for example, trig functions, the error
becomes so large that an absolute difference is likely to work better.

IOW, the best approach IMO is to allow users of higher level numerical
objects to choose the comparison semantics that better fit the domain and
the underlying types. For instance, in some scenarios and conditions, strict
comparison is the best choice.

>From this POV, the fp-comparisons in Boost.Test becomes just one option
(even if the most common).

Now, if a user is to decide which comparison semantics to use, the
vector/matrix objects themselves would only know about the interface to the
comparison protocol (being this a policy, a traits, an overloaded set of
free-functions, or whatever), so it won't include itself something like
"boost/test/floating_point_comparison.hpp".
Rather, the user would include some header that includes the that one as an
implementatin detail.

HTH

-- 
------
Fernando Cacciola
SciSoft
http://certuscode.wordpress.com
http://fcacciola.50webs.com
http://fcacciola.wordpress.com

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