From stdcxx-commits-return-167-apmail-incubator-stdcxx-commits-archive=incubator.apache.org@incubator.apache.org Sat Nov 12 00:48:22 2005 Return-Path: Delivered-To: apmail-incubator-stdcxx-commits-archive@www.apache.org Received: (qmail 58013 invoked from network); 12 Nov 2005 00:48:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 12 Nov 2005 00:48:22 -0000 Received: (qmail 46187 invoked by uid 500); 12 Nov 2005 00:48:22 -0000 Delivered-To: apmail-incubator-stdcxx-commits-archive@incubator.apache.org Received: (qmail 46174 invoked by uid 500); 12 Nov 2005 00:48:22 -0000 Mailing-List: contact stdcxx-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-commits@incubator.apache.org Received: (qmail 46163 invoked by uid 500); 12 Nov 2005 00:48:22 -0000 Delivered-To: apmail-incubator-stdcxx-cvs@incubator.apache.org Received: (qmail 46159 invoked by uid 99); 12 Nov 2005 00:48:22 -0000 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 11 Nov 2005 16:48:22 -0800 Received: (qmail 57835 invoked by uid 65534); 12 Nov 2005 00:48:01 -0000 Message-ID: <20051112004801.57813.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r332687 - /incubator/stdcxx/trunk/tests/src/valcmp.cpp Date: Sat, 12 Nov 2005 00:48:00 -0000 To: stdcxx-cvs@incubator.apache.org From: sebor@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: sebor Date: Fri Nov 11 16:47:57 2005 New Revision: 332687 URL: http://svn.apache.org/viewcvs?rev=332687&view=rev Log: 2005-11-11 Martin Sebor * valcmp.cpp (rw_dblcmp): Hacked around a missing 64-bit integer type (e.g., when long long support has been disabled). Modified: incubator/stdcxx/trunk/tests/src/valcmp.cpp Modified: incubator/stdcxx/trunk/tests/src/valcmp.cpp URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/valcmp.cpp?rev=332687&r1=332686&r2=332687&view=diff ============================================================================== --- incubator/stdcxx/trunk/tests/src/valcmp.cpp (original) +++ incubator/stdcxx/trunk/tests/src/valcmp.cpp Fri Nov 11 16:47:57 2005 @@ -741,6 +741,9 @@ } +#define Abs(x) ((x) < 0 ? -(x) : (x)) + + _TEST_EXPORT int rw_dblcmp (double x, double y) { @@ -753,11 +756,32 @@ #elif _RWSTD_DBL_SIZE == _RWSTD_LLONG_SIZE typedef _RWSTD_LONG_LONG IntT; const IntT imin = _RWSTD_LLONG_MIN; -#else - // ??? -# error no integral type of the same size as double exists #endif +#if _RWSTD_LLONG_SIZE < _RWSTD_DBL_SIZE + + if (x == y) + return 0; + + // FIXME: use integer math as in the functions above + + const double diff = x - y; + + // check absolute error + if (Abs (diff) < _RWSTD_DBL_EPSILON) + return 0; + + // check relative error + const double relerr = + Abs (x) < Abs (y) ? Abs (diff / y) : Abs (diff / x); + + if (relerr <= 0.0000001) + return 0; + + return x < y ? -1 : +1; + +#else // if !(_RWSTD_LLONG_SIZE < _RWSTD_DBL_SIZE) + if (x == y) return 0; @@ -772,12 +796,13 @@ const IntT int_diff = x_int - y_int; return int_diff; + +#endif // _RWSTD_LLONG_SIZE < _RWSTD_DBL_SIZE + } #ifndef _RWSTD_NO_LONG_DOUBLE - -# define Abs(x) ((x) < 0 ? -(x) : (x)) _TEST_EXPORT int rw_ldblcmp (long double x, long double y)