|
Boost Users : |
Subject: [Boost-users] [boost.test] Floating point comparisons
From: Anders Wang Kristensen (awk.main_at_[hidden])
Date: 2010-11-22 11:42:03
Hi,
I'm using boost.test and BOOST_CHECK_CLOSE to verify that some
matrices I compute are equal to some reference matices.
This works fine as long as no entries are zero in either matrix
(reference or computed). However, when an entry is zero,
BOOST_CHECK_CLOSE always fails, which makes sense, since relative
error is undefined in such cases.
If either entry is zero, I can use BOOST_CHECK_SMALL instead with an
absolute error:
if (ref==0.0 || val==0.0)
BOOST_CHECK_SMALL(ref - val, absolute_error);
else
BOOST_CHECK_CLOSE(ref, val, relative_error);
But is this really the best way to do this? And if this is the
standard way of doing this, shouldn't there be function in boost.test
for automating this, like:
BOOST_CHECK_NEAR(ref, value, relative_error, absolute_error);
kinds regards,
Anders
(sorry if this post appears twice)
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net