fixed_point (deprecated)  rev.2
Binary Fixed-Point Arithmetic Library in C++
elastic_fixed_point.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_ELASTIC_FIXED_POINT_H)
11 #define SG14_ELASTIC_FIXED_POINT_H 1
12 
13 #include "elastic_integer.h"
14 #include <sg14/fixed_point>
15 
17 namespace sg14 {
20  // sg14-specific definitions
21 
29 
30  template<int IntegerDigits, int FractionalDigits = 0, class Narrowest = signed>
32 
35  // sg14::make_elastic_fixed_point
36 
52 
53  template<
54  typename Narrowest = int,
55  typename Integral = int,
56  Integral Value = 0>
57  constexpr elastic_fixed_point<_impl::max(_impl::used_bits_symmetric(Value), 1), -trailing_bits(Value), Narrowest>
59  {
60  return Value;
61  }
62 
65  // sg14::make_elastic_fixed_point
66 
77 
79  template<class Narrowest = int, class Integral = int>
81  make_elastic_fixed_point(Integral value)
82  {
83  return {value};
84  }
85 
88  // sg14::literals::operator "" _elastic
89 
103 
104  namespace literals {
105  template<char... Digits>
106  constexpr auto operator "" _elastic()
107  -> decltype(make_elastic_fixed_point<int, std::intmax_t, _const_integer_impl::digits_to_integral<Digits...>::value>()) {
108  return make_elastic_fixed_point<int, std::intmax_t, _const_integer_impl::digits_to_integral<Digits...>::value>();
109  }
110  }
111 }
112 
113 #endif // SG14_ELASTIC_FIXED_POINT_H
constexpr elastic_fixed_point< _impl::max(_impl::used_bits_symmetric(Value), 1), -trailing_bits(Value), Narrowest > make_elastic_fixed_point(const_integer< Integral, Value >=const_integer< Integral, Value >{})
generate an sg14::elastic_fixed_point object of given value
Definition: elastic_fixed_point.h:58
a compile-time-only integer type like a std::integral_constant with arithmetic support ...
Definition: const_integer.h:98
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