incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Ritter" <rit...@roguewave.com>
Subject Question about comparing floats and doubles for equality
Date Thu, 05 Apr 2007 21:42:25 GMT
In reviewing the following file for some information on how to compare
floats and doubles for equality I had some questions I wanted to ask the
list.

http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/valcmp.cpp
?view=markup

I found the methods rw_fltcmp and rw_dblcmp that are implemented in
valcmp.cpp but I have a few questions about them.

In rw_fltcmp() the method starts off with the following block of code:

#if _RWSTD_SHRT_SIZE == _RWSTD_INT_SIZE
    typedef short IntT;
    const IntT imin = _RWSTD_SHRT_MIN;
#elif _RWSTD_FLT_SIZE == _RWSTD_INT_SIZE
    typedef int IntT;
    const IntT imin = _RWSTD_INT_MIN;
#elif _RWSTD_FLT_SIZE == _RWSTD_LONG_SIZE
    typedef long IntT;
    const IntT imin = _RWSTD_LONG_MIN;
#elif _RWSTD_FLT_SIZE == _RWSTD_LLONG_SIZE
    typedef _RWSTD_LONG_LONG IntT;
    const IntT imin = _RWSTD_LLONG_MIN;
#else

Why is the size of a short being compared to the size of an int when all
the other comparisons are made against float?  As a side note, that
first check seems to be missing from rw_dblcmp, is it unnecessary there?

My other question relates to rw_dblcmp.  In the method there appears to
be two different ways of checking the equality, depending on whether the
size of a long long is less than the size of a double.  Is that a
performance optimization?

Thank you for any help/insight you can provide.

Dave Ritter

Mime
View raw message