// Copyright (c) 2006 Johan Rade // Copyright (c) 2011 Paul A. Bristow To incorporate into Boost.Math // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) #ifdef _MSC_VER # pragma warning(disable : 4702) // Unreachable code. # pragma warning(disable : 4127) // expression is constant. #endif #define BOOST_TEST_MAIN #include #include #include #include #include #include #include "almost_equal.ipp" #include "s_.ipp" namespace { // the anonymous namespace resolves ambiguities on platforms // with fpclassify etc functions at global scope using namespace boost::math; using boost::math::signbit; using boost::math::changesign; using boost::math::isnan; //------------------------------------------------------------------------------ template void signed_zero_test_impl(); BOOST_AUTO_TEST_CASE(signed_zero_test) { signed_zero_test_impl(); signed_zero_test_impl(); signed_zero_test_impl(); signed_zero_test_impl(); signed_zero_test_impl(); signed_zero_test_impl(); } template void signed_zero_test_impl() { if (signbit(static_cast(-1e-6f)/(std::numeric_limits::max)()) != -0) { BOOST_MESSAGE("Signed zero is not supported on this platform."); return; } std::locale old_locale; std::locale tmp_locale( old_locale, new nonfinite_num_put(signed_zero)); std::locale new_locale(tmp_locale, new nonfinite_num_get); std::basic_stringstream ss; ss.imbue(new_locale); ValType a1 = static_cast(0); ValType a2 = (changesign)(static_cast(0)); BOOST_CHECK(!(signbit)(a1)); BOOST_CHECK((signbit)(a2)); ss << a1 << ' ' << a2; std::basic_string s = S_("0 -0"); BOOST_CHECK(ss.str() == s); ValType b1, b2; ss >> b1 >> b2; BOOST_CHECK(b1 == a1); BOOST_CHECK(b2 == a2); BOOST_CHECK(!(signbit)(b1)); BOOST_CHECK((signbit)(b2)); BOOST_CHECK(ss.rdstate() == std::ios_base::eofbit); } //------------------------------------------------------------------------------ } // anonymous namespace