CNL  2.0.2 (development)
Compositional Numeric Library
overflow_integer.h
Go to the documentation of this file.
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(CNL_OVERFLOW_INT_H)
11 #define CNL_OVERFLOW_INT_H
12 
13 #include "overflow.h"
14 
16 #include "_impl/custom_operator/native_tag.h"
17 #include "_impl/custom_operator/tagged.h"
18 #include "_impl/num_traits/from_value.h"
19 #include "_impl/num_traits/from_value_recursive.h"
20 #include "_impl/num_traits/rep_of.h"
21 #include "_impl/ostream.h"
22 #include "_impl/wrapper.h"
23 
24 #include <type_traits>
25 
27 namespace cnl {
35 
36  template<typename Rep = int, overflow_tag Tag = undefined_overflow_tag>
37  using overflow_integer = _impl::wrapper<Rep, Tag>;
38 
40  // cnl::scale<..., overflow_integer<>>
41 
42  template<int Digits, int Radix, typename Rep, overflow_tag Tag>
43  struct scale<Digits, Radix, _impl::wrapper<Rep, Tag>> {
44  private:
45  using value_type = _impl::wrapper<Rep, Tag>;
46 
47  public:
48  [[nodiscard]] constexpr auto operator()(value_type const& s) const -> decltype(_impl::from_rep<value_type>(_impl::scale<Digits, Radix>(_impl::to_rep(s))))
49  {
50  return _impl::default_scale<Digits, Radix, value_type>{}(s);
51  }
52  };
53 
55  // cnl::set_rep<Rep, OverflowTag>
56 
57  // when an _impl::wrapper wraps a non-_impl::wrapper
59  template<typename NumberRep, overflow_tag NumberTag, typename Rep>
60  requires(!_impl::is_wrapper<Rep>) struct set_rep<_impl::wrapper<NumberRep, NumberTag>, Rep>
61  : std::type_identity<_impl::wrapper<Rep, NumberTag>> {
62  };
64 
66  // cnl::set_tag<overflow_integer, OverflowTag>
67 
68  template<typename NumberRep, overflow_tag NumberTag, tag Tag>
69  struct set_tag<_impl::wrapper<NumberRep, NumberTag>, Tag>
70  : std::type_identity<_impl::wrapper<NumberRep, Tag>> {
71  };
72 }
73 
74 #endif // CNL_OVERFLOW_INT_H
cnl::overflow_integer
_impl::wrapper< Rep, Tag > overflow_integer
An integer for which out-of-range arithmetic results in overflow.
Definition: overflow_integer.h:37
definition.h
primary templates providing basis for arithmetic operator customization points
cnl
compositional numeric library
Definition: abort.h:15
overflow.h
essential definitions related to overflow detection and handling