Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:36

0001 #ifndef BOOST_SAFE_NUMERICS_NATIVE_HPP
0002 #define BOOST_SAFE_NUMERICS_NATIVE_HPP
0003 
0004 //  Copyright (c) 2012 Robert Ramey
0005 //
0006 // Distributed under the Boost Software License, Version 1.0. (See
0007 // accompanying file LICENSE_1_0.txt or copy at
0008 // http://www.boost.org/LICENSE_1_0.txt)
0009 
0010 #include <type_traits>
0011 #include <limits>
0012 
0013 // policy which creates results types and values equal to that of C++ promotions.
0014 // When used in conjunction with a desired exception policy, traps errors but
0015 // does not otherwise alter the results produced by the program using it.
0016 namespace boost {
0017 namespace safe_numerics {
0018 
0019 struct native {
0020 public:
0021     // arithmetic operators
0022     template<typename T, typename U>
0023     struct addition_result {
0024         using type = decltype(
0025             typename base_type<T>::type()
0026             + typename base_type<U>::type()
0027         );
0028     };
0029     template<typename T, typename U>
0030     struct subtraction_result {
0031         using type = decltype(
0032             typename base_type<T>::type()
0033             - typename base_type<U>::type()
0034         );
0035     };
0036     template<typename T, typename U>
0037     struct multiplication_result {
0038         using type = decltype(
0039             typename base_type<T>::type()
0040             * typename base_type<U>::type()
0041         );
0042     };
0043     template<typename T, typename U>
0044     struct division_result {
0045         using type = decltype(
0046             typename base_type<T>::type()
0047             / typename base_type<U>::type()
0048         );
0049     };
0050     template<typename T, typename U>
0051     struct modulus_result {
0052         using type = decltype(
0053             typename base_type<T>::type()
0054             % typename base_type<U>::type()
0055         );
0056     };
0057     // note: comparison_result (<, >, ...) is special.
0058     // The return value is always a bool.  The type returned here is
0059     // the intermediate type applied to make the values comparable.
0060     template<typename T, typename U>
0061     struct comparison_result {
0062         using type = decltype(
0063             typename base_type<T>::type()
0064             + typename base_type<U>::type()
0065         );
0066     };
0067 
0068     // shift operators
0069     template<typename T, typename U>
0070     struct left_shift_result {
0071         using type = decltype(
0072             typename base_type<T>::type()
0073             << typename base_type<U>::type()
0074         );
0075     };
0076     template<typename T, typename U>
0077     struct right_shift_result {
0078         using type = decltype(
0079             typename base_type<T>::type()
0080             >> typename base_type<U>::type()
0081         );
0082     };
0083     // bitwise operators
0084     template<typename T, typename U>
0085     struct bitwise_or_result {
0086         using type = decltype(
0087             typename base_type<T>::type()
0088             | typename base_type<U>::type()
0089         );
0090     };
0091     template<typename T, typename U>
0092     struct bitwise_and_result {
0093         using type = decltype(
0094             typename base_type<T>::type()
0095             & typename base_type<U>::type()
0096         );
0097     };
0098     template<typename T, typename U>
0099     struct bitwise_xor_result {
0100         using type = decltype(
0101             typename base_type<T>::type()
0102             ^ typename base_type<U>::type()
0103         );
0104     };
0105 };
0106 
0107 } // safe_numerics
0108 } // boost
0109 
0110 #endif // BOOST_SAFE_NUMERICS_NATIVE_HPP