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');
114 template <
unsigned n>
117 private metal::bool_<(n <= 32)>::check_t
119 public Integer< int_s<n> >
121 public internal::value_like_< int,
122 typename internal::encoding_signed_<n>::ret,
133 int_s(const mln::literal::zero_t&);
134 int_s& operator=(const mln::literal::zero_t&);
135 int_s(const mln::literal::one_t&);
136 int_s& operator=(const mln::literal::one_t&);
140 operator int() const;
143 int_s<n>& operator=(int i);
146 static const int_s<n> zero;
149 static const int_s<n> one;
152 typedef typename internal::encoding_signed_<n>::ret enc_;
158 template <> struct int_s<0>;
159 template <> struct int_s<1>;
170 template <unsigned n>
171 std::ostream& operator<<(std::ostream& ostr, const int_s<n>& i);
175 # ifndef MLN_INCLUDE_ONLY
177 template <unsigned n>
183 template <unsigned n>
185 int_s<n>::operator int() const
190 template <unsigned n>
192 int_s<n>::int_s(int i)
194 static const int max = int(metal::math::pow_int<2, n-1>::value) - 1;
195 static const int min = - max;
196 mln_precondition(i >= min);
197 mln_precondition(i <= max);
201 this->v_ = static_cast<enc_>(i);
204 template <unsigned n>
207 int_s<n>::operator=(int i)
209 static const int max = int(metal::math::pow_int<2, n-1>::value) - 1;
210 static const int min = - max;
211 mln_precondition(i >= min);
212 mln_precondition(i <= max);
216 this->v_ = static_cast<enc_>(i);
220 template <unsigned n>
227 template <
unsigned n>
236 template <
unsigned n>
243 template <
unsigned n>
252 template <
unsigned n>
253 const int_s<n> int_s<n>::zero = 0;
255 template <
unsigned n>
256 const int_s<n> int_s<n>::one = 1;
258 template <
unsigned n>
260 std::ostream& operator<<(std::ostream& ostr, const int_s<n>& i)
265 # endif // ! MLN_INCLUDE_ONLY
272 #endif // ! MLN_VALUE_INT_S_HH