CNL  2.0.2 (development)
Compositional Numeric Library
static_number.h
Go to the documentation of this file.
1 
2 // Copyright John McFarlane 2015 - 2018.
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 
7 #if !defined(CNL_STATIC_NUBER_H)
8 #define CNL_STATIC_NUBER_H
9 
12 
13 #include "_impl/static_integer.h"
14 #include "_impl/wrapper/tag_of.h"
15 #include "integer.h"
16 #include "scaled_integer.h"
17 
18 #include <limits>
19 
21 namespace cnl {
31  template<
32  int Digits, int Exponent = 0, rounding_tag RoundingTag = nearest_rounding_tag,
33  overflow_tag OverflowTag = undefined_overflow_tag, integer Narrowest = int>
35  _impl::static_integer<Digits, RoundingTag, OverflowTag, Narrowest>, power<Exponent>>;
36 
38  template<
39  rounding_tag RoundingTag = nearest_rounding_tag, overflow_tag OverflowTag = undefined_overflow_tag,
40  integer Narrowest = int, class Input = int>
41  [[nodiscard]] constexpr auto make_static_number(Input const& input)
42  -> static_number<std::numeric_limits<Input>::digits, 0, RoundingTag, OverflowTag, Narrowest>
43  {
44  return input;
45  }
46 
48  template<
49  rounding_tag RoundingTag = _impl::tag_of_t<rounding_integer<>>,
50  overflow_tag OverflowTag = _impl::tag_of_t<overflow_integer<>>, integer Narrowest = int,
51  class Input = int, CNL_IMPL_CONSTANT_VALUE_TYPE Value>
52  [[nodiscard]] constexpr auto make_static_number(constant<Value> const&) -> static_number<
53  _impl::used_digits(Value) - trailing_bits(Value), trailing_bits(Value), RoundingTag,
54  OverflowTag, Narrowest>
55  {
56  return constant<Value>{};
57  }
58 }
59 
60 #endif // CNL_STATIC_NUBER_H
scaled_integer.h
all definitions related to the cnl::scaled_integer type
cnl::undefined_overflow_tag
tag to specify undefined-behavior-on-overflow behavior in arithemtic operations
Definition: undefined.h:31
cnl
compositional numeric library
Definition: abort.h:15
cnl::nearest_rounding_tag
tag to specify round-to-nearest behavior in arithemtic operations
Definition: nearest_rounding_tag.h:26
cnl::static_number
scaled_integer< _impl::static_integer< Digits, RoundingTag, OverflowTag, Narrowest >, power< Exponent > > static_number
a general-purpose fixed-point real number type
Definition: static_number.h:35
cnl::scaled_integer
_impl::wrapper< Rep, Scale > scaled_integer
literal real number approximation that uses fixed-point arithmetic
Definition: definition.h:52
cnl::constant
type whose value is also its non-type template parameter
Definition: constant.h:44
cnl::make_static_number
constexpr auto make_static_number(Input const &input) -> static_number< std::numeric_limits< Input >::digits, 0, RoundingTag, OverflowTag, Narrowest >
constructs a static_number from a given variable
Definition: static_number.h:41
cnl::power
tag representing the scaling of an integer by a fixed factor
Definition: declaration.h:13