26 #ifndef MLN_VALUE_INT_U_SAT_HH
27 # define MLN_VALUE_INT_U_SAT_HH
34 # include <mln/metal/math/pow.hh>
35 # include <mln/value/internal/value_like.hh>
36 # include <mln/value/concept/integer.hh>
37 # include <mln/value/internal/encoding.hh>
38 # include <mln/value/int_u.hh>
39 # include <mln/trait/value_.hh>
40 # include <mln/debug/format.hh>
49 template <
unsigned n>
struct int_u_sat;
56 struct value_< mln::value::int_u_sat<n> >
68 typedef trait::value::nature::integer
nature;
69 typedef trait::value::kind::data
kind;
71 typedef mln_value_quant_from_(card) quant;
73 typedef
unsigned comp;
106 operator int()
const;
131 template <> struct int_u_sat<1>;
141 template <
unsigned n>
142 std::ostream& operator<<(std::ostream& ostr, const int_u_sat<n>& i);
145 # ifndef MLN_INCLUDE_ONLY
147 template <
unsigned n>
153 template <
unsigned n>
157 static const unsigned max_ = mln_max(
int_u<n>);
162 else if (static_cast<unsigned>(i) > max_)
163 this->v_ =
static_cast<enc_
>(max_);
165 this->v_ =
static_cast<enc_
>(i);
168 template <
unsigned n>
175 template <
unsigned n>
178 int_u_sat<n>::operator=(
int i)
180 static const unsigned max_ = mln_max(
int_u<n>);
185 else if (static_cast<unsigned>(i) > max_)
186 this->v_ =
static_cast<enc_
>(max_);
188 this->v_ =
static_cast<enc_
>(i);
192 template <
unsigned n>
197 int v =
int(this->v_) + i;
202 template <
unsigned n>
207 int v =
int(this->v_) - i;
212 template <
unsigned n>
213 const int_u_sat<n> int_u_sat<n>::zero = 0;
215 template <
unsigned n>
216 const int_u_sat<n> int_u_sat<n>::one = 1;
218 template <
unsigned n>
220 std::ostream& operator<<(std::ostream& ostr, const int_u_sat<n>& i)
225 # endif // ! MLN_INCLUDE_ONLY
232 #endif // ! MLN_VALUE_INT_U_SAT_HH