Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71285 - trunk/libs/math/test
From: pbristow_at_[hidden]
Date: 2011-04-15 10:58:44


Author: pbristow
Date: 2011-04-15 10:58:43 EDT (Fri, 15 Apr 2011)
New Revision: 71285
URL: http://svn.boost.org/trac/boost/changeset/71285

Log:
Added changesign
Text files modified:
   trunk/libs/math/test/test_sign.cpp | 21 ++++++++++++++++++++-
   1 files changed, 20 insertions(+), 1 deletions(-)

Modified: trunk/libs/math/test/test_sign.cpp
==============================================================================
--- trunk/libs/math/test/test_sign.cpp (original)
+++ trunk/libs/math/test/test_sign.cpp 2011-04-15 10:58:43 EDT (Fri, 15 Apr 2011)
@@ -1,5 +1,5 @@
 // Copyright John Maddock 2008
-
+// (C) Copyright Paul A. Bristow 2011 (added tests for changesign)
 // Use, modification and distribution are subject to the
 // Boost Software License, Version 1.0.
 // (See accompanying file LICENSE_1_0.txt
@@ -27,6 +27,15 @@
    RealType c = -1;
    BOOST_CHECK_EQUAL((boost::math::signbit)(a), 0);
    BOOST_CHECK_EQUAL((boost::math::sign)(a), 0);
+ BOOST_CHECK_EQUAL((boost::math::changesign)(b), RealType(-1));
+ BOOST_CHECK_EQUAL((boost::math::changesign)(c), RealType(+1));
+ BOOST_CHECK_EQUAL((boost::math::changesign)(a), RealType(0));
+
+ // Compare to formula for changsign(x) = copysign(x, signbit(x) ? 1.0 : -1.0)
+ BOOST_CHECK_EQUAL((boost::math::changesign)(b),
+ boost::math::copysign(b, boost::math::signbit(b) ? RealType(1.) : RealType(-1.) ));
+
+
    BOOST_CHECK_EQUAL((boost::math::copysign)(b, a), RealType(1));
    BOOST_CHECK_EQUAL((boost::math::copysign)(c, a), RealType(1));
    a = 1;
@@ -49,6 +58,7 @@
    BOOST_CHECK_EQUAL((boost::math::sign)(a), -1);
    BOOST_CHECK_EQUAL((boost::math::copysign)(b, a), RealType(-1));
    BOOST_CHECK_EQUAL((boost::math::copysign)(c, a), RealType(-1));
+
    if(std::numeric_limits<RealType>::has_infinity)
    {
       a = std::numeric_limits<RealType>::infinity();
@@ -56,11 +66,14 @@
       BOOST_CHECK_EQUAL((boost::math::sign)(a), 1);
       BOOST_CHECK_EQUAL((boost::math::copysign)(b, a), RealType(1));
       BOOST_CHECK_EQUAL((boost::math::copysign)(c, a), RealType(1));
+ BOOST_CHECK_EQUAL((boost::math::changesign)(a), -a);
+
       a = -std::numeric_limits<RealType>::infinity();
       BOOST_CHECK((boost::math::signbit)(a) != 0);
       BOOST_CHECK_EQUAL((boost::math::sign)(a), -1);
       BOOST_CHECK_EQUAL((boost::math::copysign)(b, a), RealType(-1));
       BOOST_CHECK_EQUAL((boost::math::copysign)(c, a), RealType(-1));
+ BOOST_CHECK_EQUAL((boost::math::changesign)(a), -a);
    }
 #if !defined(__SUNPRO_CC) && !defined(BOOST_INTEL)
    if(std::numeric_limits<RealType>::has_quiet_NaN)
@@ -70,11 +83,17 @@
       BOOST_CHECK_EQUAL((boost::math::sign)(a), 1);
       BOOST_CHECK_EQUAL((boost::math::copysign)(b, a), RealType(1));
       BOOST_CHECK_EQUAL((boost::math::copysign)(c, a), RealType(1));
+ // BOOST_CHECK_EQUAL((boost::math::changesign)(a), -a); // NaN comparison fails always!
+ BOOST_CHECK_EQUAL((boost::math::signbit)((boost::math::changesign)(a)), 1);
+
       a = -std::numeric_limits<RealType>::quiet_NaN();
       BOOST_CHECK((boost::math::signbit)(a) != 0);
       BOOST_CHECK_EQUAL((boost::math::sign)(a), -1);
       BOOST_CHECK_EQUAL((boost::math::copysign)(b, a), RealType(-1));
       BOOST_CHECK_EQUAL((boost::math::copysign)(c, a), RealType(-1));
+ //BOOST_CHECK_EQUAL((boost::math::changesign)(a), -a); // NaN comparison fails always!
+ BOOST_CHECK_EQUAL((boost::math::signbit)((boost::math::changesign)(a)), 0);
+
    }
 #endif
    //


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk