fixed_point (deprecated)  rev.2
Binary Fixed-Point Arithmetic Library in C++
fixed_point_named.h
1 
2 // Copyright John McFarlane 2015 - 2016.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file ../LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 
9 
10 #if !defined(SG14_FIXED_POINT_NAMED_H)
11 #define SG14_FIXED_POINT_NAMED_H 1
12 
13 #include "common.h"
14 
15 #include "fixed_point_arithmetic.h"
16 
18 namespace sg14 {
19 
31 
32  template<class RhsRep, int RhsExponent>
33  constexpr auto negate(const fixed_point<RhsRep, RhsExponent>& rhs)
34  -> fixed_point<decltype(-rhs.data()), RhsExponent>
35  {
36  using result_type = fixed_point<decltype(-rhs.data()), RhsExponent>;
37  return result_type::from_data(-rhs.data());
38  }
39 
51 
52  template<class Lhs, class Rhs>
53  constexpr auto add(const Lhs& lhs, const Rhs& rhs)
54  -> decltype(_impl::fp::operate<_impl::fp::named_function_tag>(lhs, rhs, _impl::add_tag))
55  {
56  return _impl::fp::operate<_impl::fp::named_function_tag>(lhs, rhs, _impl::add_tag);
57  }
58 
70 
71  template<class Lhs, class Rhs>
72  constexpr auto subtract(const Lhs& lhs, const Rhs& rhs)
73  -> decltype(_impl::fp::operate<_impl::fp::named_function_tag>(lhs, rhs, _impl::subtract_tag))
74  {
75  return _impl::fp::operate<_impl::fp::named_function_tag>(lhs, rhs, _impl::subtract_tag);
76  }
77 
89 
90  template<class Lhs, class Rhs>
91  constexpr auto multiply(const Lhs& lhs, const Rhs& rhs)
92  -> decltype(_impl::fp::operate<_impl::fp::named_function_tag>(lhs, rhs, _impl::multiply_tag))
93  {
94  return _impl::fp::operate<_impl::fp::named_function_tag>(lhs, rhs, _impl::multiply_tag);
95  }
96 
108 
109  template<class Lhs, class Rhs>
110  constexpr auto divide(const Lhs& lhs, const Rhs& rhs)
111  -> decltype(_impl::fp::operate<_impl::fp::division_named_function_tag>(lhs, rhs, _impl::divide_tag))
112  {
113  return _impl::fp::operate<_impl::fp::division_named_function_tag>(lhs, rhs, _impl::divide_tag);
114  }
115 }
116 
117 #endif // SG14_FIXED_POINT_NAMED_H
constexpr auto divide(const Lhs &lhs, const Rhs &rhs) -> decltype(_impl::fp::operate< _impl::fp::division_named_function_tag >(lhs, rhs, _impl::divide_tag))
calculates the quotient of two fixed_point values
Definition: fixed_point_named.h:110
constexpr auto negate(const fixed_point< RhsRep, RhsExponent > &rhs) -> fixed_point< decltype(-rhs.data()), RhsExponent >
calculates the negative of a fixed_point value
Definition: fixed_point_named.h:33
literal real number approximation that uses fixed-point arithmetic
Definition: fixed_point_type.h:20
study group 14 of the C++ working group
Definition: const_integer.h:22