27 #ifndef MLN_VALUE_INT_S_HH
28 # define MLN_VALUE_INT_S_HH
34 # include <mln/value/ops.hh>
36 # include <mln/metal/math/pow.hh>
37 # include <mln/value/internal/value_like.hh>
38 # include <mln/value/concept/integer.hh>
39 # include <mln/value/internal/encoding.hh>
40 # include <mln/trait/value_.hh>
41 # include <mln/trait/all.hh>
42 # include <mln/debug/format.hh>
52 template <
unsigned n>
struct int_s;
70 struct value_< mln::value::int_s<n> >
79 card = mln_value_card_from_(n) - 1
82 typedef trait::value::nature::integer
nature;
83 typedef trait::value::kind::data
kind;
84 typedef mln_value_quant_from_(card) quant;
86 static const self_
max() {
return mln_value_card_from_(n) / 2 - 1; }
87 static const self_
min() {
return -
max(); }
88 static const self_ epsilon() {
return 0; }
94 static const char* name()
96 static std::string s = std::string(
"int_s").append(1, n +
'0');
117 template <
unsigned n>
120 private metal::bool_<(n <= 32)>::check_t
122 public Integer< int_s<n> >
124 public internal::value_like_< int,
125 typename internal::encoding_signed_<n>::ret,
136 int_s(const mln::literal::zero_t&);
137 int_s& operator=(const mln::literal::zero_t&);
138 int_s(const mln::literal::one_t&);
139 int_s& operator=(const mln::literal::one_t&);
143 operator int() const;
146 int_s<n>& operator=(int i);
149 static const int_s<n> zero;
152 static const int_s<n> one;
155 typedef typename internal::encoding_signed_<n>::ret enc_;
161 template <> struct int_s<0>;
162 template <> struct int_s<1>;
173 template <unsigned n>
174 std::ostream& operator<<(std::ostream& ostr, const int_s<n>& i);
178 # ifndef MLN_INCLUDE_ONLY
180 template <unsigned n>
186 template <unsigned n>
188 int_s<n>::operator int() const
193 template <unsigned n>
195 int_s<n>::int_s(int i)
197 static const int max = int(metal::math::pow_int<2, n-1>::value) - 1;
198 static const int min = - max;
199 mln_precondition(i >= min);
200 mln_precondition(i <= max);
204 this->v_ = static_cast<enc_>(i);
207 template <unsigned n>
210 int_s<n>::operator=(int i)
212 static const int max = int(metal::math::pow_int<2, n-1>::value) - 1;
213 static const int min = - max;
214 mln_precondition(i >= min);
215 mln_precondition(i <= max);
219 this->v_ = static_cast<enc_>(i);
223 template <unsigned n>
230 template <
unsigned n>
239 template <
unsigned n>
246 template <
unsigned n>
255 template <
unsigned n>
256 const int_s<n> int_s<n>::zero = 0;
258 template <
unsigned n>
259 const int_s<n> int_s<n>::one = 1;
261 template <
unsigned n>
263 std::ostream& operator<<(std::ostream& ostr, const int_s<n>& i)
268 # endif // ! MLN_INCLUDE_ONLY
275 #endif // ! MLN_VALUE_INT_S_HH