CNL  2.0.2 (development)
Compositional Numeric Library
numeric_limits.h
Go to the documentation of this file.
1 
2 // Copyright John McFarlane 2021.
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(CNL_IMPL_SCALED_INTEGER_NUMERIC_LIMITS_H)
11 #define CNL_IMPL_SCALED_INTEGER_NUMERIC_LIMITS_H
12 
13 #include "definition.h"
14 #include "from_rep.h"
15 
16 #include <limits>
17 
19 namespace std {
21  // std::numeric_limits of cnl::scaled_integer
22 
23  // note: some members are guessed,
24  // some are temporary (assuming rounding style, traps etc.)
25  // and some are undefined
26  template<typename Rep, int Exponent, int Radix>
27  struct numeric_limits<cnl::scaled_integer<Rep, cnl::power<Exponent, Radix>>>
28  : numeric_limits<Rep> {
29  private:
31  using rep_numeric_limits = numeric_limits<Rep>;
32 
33  public:
34  // standard members
35 
36  [[nodiscard]] static constexpr auto min() noexcept
37  {
38  return cnl::_impl::from_rep<value_type>(Rep{1});
39  }
40 
41  [[nodiscard]] static constexpr auto max() noexcept
42  {
43  return cnl::_impl::from_rep<value_type>(rep_numeric_limits::max());
44  }
45 
46  [[nodiscard]] static constexpr auto lowest() noexcept
47  {
48  return cnl::_impl::from_rep<value_type>(rep_numeric_limits::lowest());
49  }
50 
51  static constexpr bool is_specialized = true;
52 
53  static constexpr bool is_integer = false;
54 
55  [[nodiscard]] static constexpr auto epsilon() noexcept
56  {
57  return cnl::_impl::from_rep<value_type>(Rep{1});
58  }
59 
60  [[nodiscard]] static constexpr auto round_error() noexcept
61  {
62  return cnl::_impl::from_rep<value_type>(Rep{0});
63  }
64 
65  [[nodiscard]] static constexpr auto infinity() noexcept
66  {
67  return cnl::_impl::from_rep<value_type>(Rep{0});
68  }
69 
70  [[nodiscard]] static constexpr auto
71  quiet_NaN() noexcept // NOLINT(readability-identifier-naming)
72  {
73  return cnl::_impl::from_rep<value_type>(Rep{0});
74  }
75 
76  [[nodiscard]] static constexpr auto
77  signaling_NaN() noexcept // NOLINT(readability-identifier-naming)
78  {
79  return cnl::_impl::from_rep<value_type>(Rep{0});
80  }
81 
82  [[nodiscard]] static constexpr auto denorm_min() noexcept
83  {
84  return cnl::_impl::from_rep<value_type>(Rep{1});
85  }
86  };
87 }
88 
89 #endif // CNL_IMPL_SCALED_INTEGER_NUMERIC_LIMITS_H
std::numeric_limits::quiet_NaN
T quiet_NaN(T... args)
std::numeric_limits::lowest
T lowest(T... args)
std::numeric_limits::infinity
T infinity(T... args)
std::numeric_limits::round_error
T round_error(T... args)
cnl
compositional numeric library
Definition: abort.h:15
std::numeric_limits::signaling_NaN
T signaling_NaN(T... args)
std::numeric_limits::epsilon
T epsilon(T... args)
std::numeric_limits::min
T min(T... args)
std
STL namespace.
std::numeric_limits::denorm_min
T denorm_min(T... args)
cnl::scaled_integer
_impl::wrapper< Rep, Scale > scaled_integer
literal real number approximation that uses fixed-point arithmetic
Definition: definition.h:52
std::numeric_limits::max
T max(T... args)