Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
1 // © Copyright Fernando Luis Cacciola Carballal 2000-2004
2 // Use, modification, and distribution is subject to the Boost Software
3 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See library home page at http://www.boost.org/libs/numeric/conversion
8 // Contact the author at: fernando_cacciola@hotmail.com
10 #ifndef BOOST_NUMERIC_CONVERSION_CONVERTER_POLICIES_FLC_12NOV2002_HPP
11 #define BOOST_NUMERIC_CONVERSION_CONVERTER_POLICIES_FLC_12NOV2002_HPP
13 #include <typeinfo> // for std::bad_cast
15 #include <cmath> // for std::floor and std::ceil
19 #include "boost/type_traits/is_arithmetic.hpp"
21 #include "boost/mpl/if.hpp"
22 #include "boost/mpl/integral_c.hpp"
24 namespace boost { namespace numeric
30 typedef S source_type ;
32 typedef typename mpl::if_< is_arithmetic<S>,S,S const&>::type argument_type ;
34 static source_type nearbyint ( argument_type s )
36 #if !defined(BOOST_NO_STDC_NAMESPACE)
41 return s < static_cast<S>(0) ? ceil(s) : floor(s) ;
44 typedef mpl::integral_c< std::float_round_style, std::round_toward_zero> round_style ;
52 typedef S source_type ;
54 typedef typename mpl::if_< is_arithmetic<S>,S,S const&>::type argument_type ;
56 static source_type nearbyint ( argument_type s )
58 #if !defined(BOOST_NO_STDC_NAMESPACE)
65 typedef mpl::integral_c< std::float_round_style, std::round_toward_neg_infinity> round_style ;
71 typedef S source_type ;
73 typedef typename mpl::if_< is_arithmetic<S>,S,S const&>::type argument_type ;
75 static source_type nearbyint ( argument_type s )
77 #if !defined(BOOST_NO_STDC_NAMESPACE)
84 typedef mpl::integral_c< std::float_round_style, std::round_toward_infinity> round_style ;
90 typedef S source_type ;
92 typedef typename mpl::if_< is_arithmetic<S>,S,S const&>::type argument_type ;
94 static source_type nearbyint ( argument_type s )
96 // Algorithm contributed by Guillaume Melquiond
98 #if !defined(BOOST_NO_STDC_NAMESPACE)
103 // only works inside the range not at the boundaries
107 S rt = (s - prev) - (next - s); // remainder type
114 else if ( rt > zero )
118 bool is_prev_even = two * floor(prev / two) == prev ;
119 return ( is_prev_even ? prev : next ) ;
123 typedef mpl::integral_c< std::float_round_style, std::round_to_nearest> round_style ;
127 enum range_check_result
134 class bad_numeric_cast : public std::bad_cast
138 virtual const char * what() const throw()
139 { return "bad numeric conversion: overflow"; }
142 class negative_overflow : public bad_numeric_cast
146 virtual const char * what() const throw()
147 { return "bad numeric conversion: negative overflow"; }
149 class positive_overflow : public bad_numeric_cast
153 virtual const char * what() const throw()
154 { return "bad numeric conversion: positive overflow"; }
157 struct def_overflow_handler
159 void operator() ( range_check_result r ) // throw(negative_overflow,positive_overflow)
161 if ( r == cNegOverflow )
162 throw negative_overflow() ;
163 else if ( r == cPosOverflow )
164 throw positive_overflow() ;
168 struct silent_overflow_handler
170 void operator() ( range_check_result ) {} // throw()
173 template<class Traits>
176 typedef typename Traits::result_type result_type ;
177 typedef typename Traits::argument_type argument_type ;
179 static result_type low_level_convert ( argument_type s ) { return static_cast<result_type>(s) ; }
182 struct UseInternalRangeChecker {} ;
184 } } // namespace boost::numeric