Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:52:41

0001 //  (C) Copyright Gennadiy Rozental 2001.
0002 //  Distributed under the Boost Software License, Version 1.0.
0003 //  (See accompanying file LICENSE_1_0.txt or copy at
0004 //  http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 //  See http://www.boost.org/libs/test for the library home page.
0007 //
0008 //  File        : $RCSfile$
0009 //
0010 //  Version     : $Revision: 74248 $
0011 //
0012 //  Description : FPC tools tolerance holder
0013 // ***************************************************************************
0014 
0015 #ifndef BOOST_TEST_TOOLS_FPC_TOLERANCE_HPP_121612GER
0016 #define BOOST_TEST_TOOLS_FPC_TOLERANCE_HPP_121612GER
0017 
0018 // Boost Test
0019 #include <boost/test/tree/decorator.hpp>
0020 #include <boost/test/tools/floating_point_comparison.hpp>
0021 
0022 #include <boost/test/detail/suppress_warnings.hpp>
0023 
0024 //____________________________________________________________________________//
0025 
0026 namespace boost {
0027 namespace test_tools {
0028 
0029 namespace fpc = math::fpc;
0030 
0031 // ************************************************************************** //
0032 // **************     floating point comparison tolerance      ************** //
0033 // ************************************************************************** //
0034 
0035 template<typename FPT>
0036 inline FPT&
0037 fpc_tolerance()
0038 {
0039     static FPT s_value = 0;
0040     return s_value;
0041 }
0042 
0043 //____________________________________________________________________________//
0044 
0045 template<typename FPT>
0046 struct local_fpc_tolerance {
0047     local_fpc_tolerance( FPT fraction_tolerance ) : m_old_tolerance( fpc_tolerance<FPT>() )
0048     {
0049         fpc_tolerance<FPT>() = fraction_tolerance;
0050     }
0051 
0052     ~local_fpc_tolerance()
0053     {
0054         if( m_old_tolerance != (FPT)-1 )
0055             fpc_tolerance<FPT>() = m_old_tolerance;
0056     }
0057 
0058 private:
0059     // Data members
0060     FPT         m_old_tolerance;
0061 };
0062 
0063 //____________________________________________________________________________//
0064 
0065 } // namespace test_tools
0066 
0067 // ************************************************************************** //
0068 // **************             decorator::tolerance             ************** //
0069 // ************************************************************************** //
0070 
0071 namespace unit_test {
0072 namespace decorator {
0073 
0074 template<typename FPT>
0075 inline fixture_t
0076 tolerance( FPT v )
0077 {
0078     return fixture_t( test_unit_fixture_ptr(
0079         new unit_test::class_based_fixture<test_tools::local_fpc_tolerance<FPT>,FPT>( v ) ) );
0080 }
0081 
0082 //____________________________________________________________________________//
0083 
0084 template<typename FPT>
0085 inline fixture_t
0086 tolerance( test_tools::fpc::percent_tolerance_t<FPT> v )
0087 {
0088     return fixture_t( test_unit_fixture_ptr(
0089         new unit_test::class_based_fixture<test_tools::local_fpc_tolerance<FPT>,FPT>( boost::math::fpc::fpc_detail::fraction_tolerance<FPT>( v ) ) ) );
0090 }
0091 
0092 //____________________________________________________________________________//
0093 
0094 } // namespace decorator
0095 
0096 using decorator::tolerance;
0097 
0098 } // namespace unit_test
0099 } // namespace boost
0100 
0101 #include <boost/test/detail/enable_warnings.hpp>
0102 
0103 #endif // BOOST_TEST_TOOLS_FPC_TOLERANCE_HPP_121612GER