stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Ritter" <>
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

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:

    typedef short IntT;
    const IntT imin = _RWSTD_SHRT_MIN;
    typedef int IntT;
    const IntT imin = _RWSTD_INT_MIN;
    typedef long IntT;
    const IntT imin = _RWSTD_LONG_MIN;
    typedef _RWSTD_LONG_LONG IntT;
    const IntT imin = _RWSTD_LLONG_MIN;

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

View raw message