Dealing with high precision float comparison; 5+ ULPs across multiple machines.

1,223 views
Skip to first unread message

khunkhun

unread,
Apr 10, 2009, 1:35:33 AM4/10/09
to Google C++ Testing Framework
How do you guys (google/non google folks) deal with floating point
comparisons (using ASSERT_NEAR in your test code) across various test
machines (where float values will differ based on system
configuration) in an automated pre-flight build-->test-->checkin
environment , given delta needs to be within 5+ ULPs?

Kindest Regards,
Sonu
<This Is My First Post>

Vlad Losev

unread,
Apr 10, 2009, 1:52:20 AM4/10/09
to khunkhun, Google C++ Testing Framework
Hi Sonu,

Google Test has the EXPECT_FLOAT_EQ and the EXPECT_DOUBLE_EQ macros, which check that the two values are within 4 ULPs. Or you can define your own comparison predicate and use it with the EXPECT_PRED_FORMAT2() macro. Is this what you are looking for?
Regards,
Vlad.

khunkhun

unread,
Apr 10, 2009, 2:04:56 AM4/10/09
to Google C++ Testing Framework
Hi Vlad,
Thanks very much for the quick response, but I was more interested in
techniques dealing with value difference across multiple systems;
since float values may differ amongst a set of machines. For example,
the expected value may differ for a given algorithm depending on
system processor...etc. Also note, the macros you mentioned only go up
to 4 ULPs.

Kindest Regards,
Sonu

On Apr 9, 10:52 pm, Vlad Losev <vladlo...@gmail.com> wrote:
> Hi Sonu,
>
> Google Test has the EXPECT_FLOAT_EQ and the
> EXPECT_DOUBLE_EQ<http://code.google.com/p/googletest/wiki/GoogleTestAdvancedGuide#Floa...>macros,
> which check that the two values are within 4 ULPs. Or you can define
> your own comparison predicate and use it with the EXPECT_PRED_FORMAT2()
> macro. Is this what you are looking for?
>

Zhanyong Wan (λx.x x)

unread,
Apr 10, 2009, 2:17:08 AM4/10/09
to khunkhun, Google C++ Testing Framework
Hi Sonu,

In your case, the optimal error bound depends on many factors: the
machine architecture, your algorithm, how precise you need the result
to be, etc. You need to do you own error analysis and determine what
the error bound should be, and use EXPECT_NEAR with the error bound
you determined.

Hope this helps,

--
Zhanyong

khunkhun

unread,
Apr 10, 2009, 2:32:42 AM4/10/09
to Google C++ Testing Framework
Thanks for your quick reply Zhanyong,

Yup...looks like there is no silver bullet for this problem...so I
guess I will have to do a bunch of #ifdefs for a given system set or
do some logic based on environment variables, since the values are
sure to vary a bit across given systems...even with same machine
architecture.

Thanks again...better get to work.

Kindest Regards,
Sonu
Reply all
Reply to author
Forward
0 new messages