* mln/value/unsignedh.hh,
* tests/value/unsignedh.cc: Remove.
* mln/value/intsub.hh,
* tests/value/intsub.cc: New.
* tests/value/Makefile.am: Change target name.
---
milena/ChangeLog | 12 +
milena/mln/value/intsub.hh | 569 ++++++++++++++++++++++++
milena/mln/value/unsignedh.hh | 415 -----------------
milena/tests/value/Makefile.am | 4 +-
milena/tests/value/{unsignedh.cc => intsub.cc} | 46 ++-
5 files changed, 623 insertions(+), 423 deletions(-)
create mode 100644 milena/mln/value/intsub.hh
delete mode 100644 milena/mln/value/unsignedh.hh
rename milena/tests/value/{unsignedh.cc => intsub.cc} (65%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index ea274e2..24bd25c 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,17 @@
2012-10-03 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Replace unsignedh type by intsub.
+
+ * mln/value/unsignedh.hh,
+ * tests/value/unsignedh.cc: Remove.
+
+ * mln/value/intsub.hh,
+ * tests/value/intsub.cc: New.
+
+ * tests/value/Makefile.am: Change target name.
+
+2012-10-03 Guillaume Lazzara <z(a)lrde.epita.fr>
+
New routines to browse values into a value set.
* mln/accu/label_used.hh,
diff --git a/milena/mln/value/intsub.hh b/milena/mln/value/intsub.hh
new file mode 100644
index 0000000..fc269a8
--- /dev/null
+++ b/milena/mln/value/intsub.hh
@@ -0,0 +1,569 @@
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef MLN_VALUE_INTSUB_HH
+# define MLN_VALUE_INTSUB_HH
+
+/// \file
+///
+/// Define a subdivided integer value class.
+
+# include <cstdlib>
+# include <iostream>
+# include <sstream>
+# include <mln/value/internal/value_like.hh>
+# include <mln/value/internal/encoding.hh>
+# include <mln/value/internal/limits.hh>
+# include <mln/value/concept/integer.hh>
+# include <mln/value/iota.hh>
+# include <mln/value/prev.hh>
+# include <mln/value/succ.hh>
+
+
+namespace mln
+{
+
+ // Forward declaration
+ namespace value {
+ template <unsigned n> class intsub;
+ }
+
+ namespace trait
+ {
+
+ template <unsigned n>
+ struct set_precise_unary_< op::uminus, mln::value::intsub<n> >
+ {
+ typedef mln::value::intsub<n> ret;
+ };
+
+
+ template <unsigned n>
+ struct value_< mln::value::intsub<n> >
+ {
+ private:
+ typedef mln::value::intsub<n> self_;
+ typedef typename mln::value::internal::encoding_signed_<32>::ret enc_;
+ public:
+
+ enum constants_ {
+ dim = 1,
+ nbits = 32,
+ card = mln_value_card_from_(32/n) // FIXME: Really?
+ };
+
+ typedef trait::value::nature::integer nature;
+ typedef trait::value::kind::data kind;
+ typedef mln_value_quant_from_(card) quant;
+
+ static const self_ max() { return mln::value::internal::limits<int>::max() /
n; }
+ static const self_ min() { return - max(); }
+ static const self_ epsilon() { return 0; }
+
+ typedef mln::value::intsub<n> comp;
+
+ typedef mln::value::intsub<n> sum;
+
+ static const char* name()
+ {
+ static std::string
+ s = mln::value::internal::make_generic_name("intsub", n);
+ return s.c_str();
+ }
+
+ };
+
+ } // end of namespace mln::trait
+
+
+
+ namespace value
+ {
+
+ template <unsigned n>
+ class intsub
+ : public Integer< intsub<n> >,
+ public internal::value_like_< int, // Equivalent.
+ typename internal::encoding_signed_<32>::ret, // Enc.
+ int, // Interoperation.
+ intsub<n> > // Exact.
+ {
+ public:
+ intsub();
+ intsub(const intsub<n>& rhs);
+ /// Construct an intsub with value : \p int_part + 1 / \p denominator.
+ intsub(int int_part, unsigned denominator);
+ intsub(int i);
+
+ intsub<n>& operator=(const intsub<n>& rhs);
+ intsub<n>& operator=(int i);
+
+ /// Is an integer value.
+ bool is_integer() const;
+
+ /// Convert this intsub to a larger intsub type.
+ template <unsigned m>
+ operator intsub<m>();
+
+ /*! \internal Increment by value::iota::value() the
+ value to the next one.
+ */
+ void inc_();
+ /*! \internal Decrement by value::iota::value() the
+ value to the next one.
+ */
+ void dec_();
+
+ /*!\internal Return the integer part of this value.
+ */
+ int to_int() const;
+
+ /*!\internal Construct a intsub using an encoding value. */
+ static intsub<n> make_from_enc_(int enc);
+
+ /// Unary operator minus.
+ intsub<n> operator-() const;
+
+ };
+
+
+ // Safety
+ template <> struct intsub<0>;
+
+// rounding
+
+ template <unsigned n>
+ intsub<n> floor(const intsub<n>& i);
+ template <unsigned n>
+ intsub<n> ceil(const intsub<n>& i);
+
+
+// comparison
+
+ template <unsigned n>
+ bool operator==(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n, typename V>
+ bool operator==(const intsub<n>& l, const V& r);
+ template <unsigned n>
+ bool operator<=(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n>
+ bool operator!=(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n>
+ bool operator>=(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n>
+ bool operator>(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n>
+ bool operator<(const intsub<n>& l, const intsub<n>& r);
+
+// arithmetics
+
+ template <unsigned n>
+ intsub<n> operator+(const intsub<n>& l, const intsub<n>&
r);
+ template <unsigned n, typename O>
+ intsub<n> operator+(const intsub<n>& l, const O& r);
+ template <typename O, unsigned n>
+ intsub<n> operator+(const O& r, const intsub<n>& l);
+ template <unsigned n>
+ void operator+=(intsub<n>& l, const intsub<n>& r);
+ template <unsigned n, typename O>
+ void operator+=(intsub<n>& l, const O& r);
+
+ template <unsigned n>
+ intsub<n> operator-(const intsub<n>& l, const intsub<n>&
r);
+ template <unsigned n, typename O>
+ intsub<n> operator-(const intsub<n>& l, const O& r);
+ template <typename O, unsigned n>
+ intsub<n> operator-(const O& r, const intsub<n>& l);
+ template <unsigned n>
+ void operator-=(intsub<n>& l, const intsub<n>& r);
+ template <unsigned n, typename O>
+ void operator-=(intsub<n>& l, const O& r);
+
+ template <unsigned n>
+ intsub<n> operator*(const intsub<n>& l, const intsub<n>&
r);
+ template <unsigned n, typename O>
+ intsub<n> operator*(const intsub<n>& l, const O& r);
+ template <typename O, unsigned n>
+ intsub<n> operator*(const O& r, const intsub<n>& l);
+ template <unsigned n>
+ void operator*=(intsub<n>& l, const intsub<n>& r);
+ template <unsigned n, typename O>
+ void operator*=(intsub<n>& l, const O& r);
+
+// other ops
+
+ template <unsigned n>
+ intsub<n> min(const intsub<n>& u1, const intsub<n>& u2);
+ template <unsigned n>
+ intsub<n> max(const intsub<n>& u1, const intsub<n>& u2);
+ template <unsigned n>
+ intsub<n> mean(const intsub<n>& v1, const intsub<n>& v2);
+ template <unsigned n>
+ intsub<n> mean(const intsub<n>& v1, const intsub<n>& v2,
+ const intsub<n>& v3, const intsub<n>& v4);
+
+// <<
+
+ template <unsigned n>
+ std::ostream&
+ operator<<(std::ostream& ostr, const intsub<n>& i);
+
+ template <unsigned n>
+ struct iota<intsub<n> >
+ {
+ static intsub<n> value();
+ };
+
+ } // end of namespace mln::value
+
+ extern const value::intsub<2> half;
+ extern const value::intsub<4> quarter;
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // half
+
+# ifndef MLN_WO_GLOBAL_VARS
+
+ const value::intsub<2> half = value::intsub<2>(0, 2);
+ const value::intsub<4> quarter = value::intsub<4>(0, 4);
+
+# endif // ! MLN_WO_GLOBAL_VARS
+
+
+
+ namespace value
+ {
+
+ template <unsigned n>
+ intsub<n>::intsub()
+ {
+ }
+
+ template <unsigned n>
+ intsub<n>::intsub(const intsub<n>& rhs)
+ {
+ this->v_ = rhs.v_;
+ }
+
+ template <unsigned n>
+ intsub<n>::intsub(int i)
+ {
+ this->v_ = n * i;
+ }
+
+ template <unsigned n>
+ intsub<n>::intsub(int int_part, unsigned denominator)
+ {
+ // FIXME: better error handling ?
+ if (denominator > n)
+ std::abort();
+
+ this->v_ = int_part * n + denominator / n;
+ }
+
+
+ template <unsigned n>
+ intsub<n>&
+ intsub<n>::operator=(const intsub<n>& rhs)
+ {
+ this->v_ = rhs.v_;
+ return *this;
+ }
+
+ template <unsigned n>
+ intsub<n>&
+ intsub<n>::operator=(int i)
+ {
+ this->v_ = n * i;
+ return *this;
+ }
+
+ template <unsigned n>
+ intsub<n> intsub<n>::make_from_enc_(int enc)
+ {
+ intsub<n> i;
+ i.v_ = enc;
+ return i;
+ }
+
+ template <unsigned n>
+ bool
+ intsub<n>::is_integer() const
+ {
+ return this->v_ % n == 0;
+ }
+
+ template <unsigned n>
+ template <unsigned m>
+ intsub<n>::operator intsub<m>()
+ {
+ // FIXME: better error handling ?
+ if (n > m)
+ std::abort();
+ return intsub<m>::make_from_enc_(this->v_ * (m / n));
+ }
+
+ template <unsigned n>
+ void
+ intsub<n>::inc_()
+ {
+ this->v_ += iota<intsub<n> >::value().to_enc();
+ }
+
+ template <unsigned n>
+ void
+ intsub<n>::dec_()
+ {
+ this->v_ -= iota<intsub<n> >::value().to_enc();
+ }
+
+ template <unsigned n>
+ int
+ intsub<n>::to_int() const
+ {
+ return this->v_ / n;
+ }
+
+ template <unsigned n>
+ intsub<n>
+ intsub<n>::operator-() const
+ {
+ return intsub<n>::make_from_enc_(this->v_ * -1);
+ }
+
+ // Iota
+ template <unsigned n>
+ intsub<n>
+ iota<intsub<n> >::value()
+ {
+ return intsub<n>(0,n);
+ }
+
+
+// rounding
+
+
+ template <unsigned n>
+ intsub<n> floor(const intsub<n>& i)
+ {
+ return i.is_integer() ? i : value::prev(i);
+ }
+
+ template <unsigned n>
+ intsub<n> ceil(const intsub<n>& i)
+ {
+ return i.is_integer() ? i : value::succ(i);
+ }
+
+
+
+// comparison
+
+ template <unsigned n>
+ bool operator==(const intsub<n>& l, const intsub<n>& r)
+ {
+ return l.to_enc() == r.to_enc();
+ }
+
+ template <unsigned n>
+ bool operator==(const intsub<n>& l, const int& r)
+ {
+ return l == intsub<n>(r);
+ }
+
+ template <unsigned n>
+ bool operator<=(const intsub<n>& l, const intsub<n>& r)
+ {
+ return l.to_enc() <= r.to_enc();
+ }
+
+ template <unsigned n>
+ bool operator!=(const intsub<n>& l, const intsub<n>& r)
+ {
+ return ! (l == r);
+ }
+
+ template <unsigned n>
+ bool operator>=(const intsub<n>& l, const intsub<n>& r)
+ {
+ return r <= l;
+ }
+
+ template <unsigned n>
+ bool operator>(const intsub<n>& l, const intsub<n>& r)
+ {
+ return ! (l <= r);
+ }
+
+ template <unsigned n>
+ bool operator<(const intsub<n>& l, const intsub<n>& r)
+ {
+ return r > l;
+ }
+
+
+// arithmetics
+
+ template <unsigned n>
+ intsub<n> operator+(const intsub<n>& l, const intsub<n>&
r)
+ {
+ return intsub<n>::make_from_enc_(l.to_enc() + r.to_enc());
+ }
+
+ template <unsigned n>
+ intsub<n> operator+(const intsub<n>& l, int r)
+ {
+ return l + intsub<n>(r);
+ }
+
+ template <unsigned n>
+ intsub<n> operator+(int l, const intsub<n>& r)
+ {
+ return r + l;
+ }
+
+ template <unsigned n>
+ void operator+=(intsub<n>& l, const intsub<n>& r)
+ {
+ l = l + r;
+ }
+
+ template <unsigned n>
+ void operator+=(intsub<n>& l, int r)
+ {
+ l = l + intsub<n>(r);
+ }
+
+ template <unsigned n>
+ intsub<n> operator-(const intsub<n>& l, const intsub<n>&
r)
+ {
+ return intsub<n>::make_from_enc_(l.to_enc() - r.to_enc());
+ }
+
+ template <unsigned n>
+ intsub<n> operator-(const intsub<n>& l, int r)
+ {
+ return l - intsub<n>(r);
+ }
+
+ template <unsigned n>
+ intsub<n> operator-(int l, const intsub<n>& r)
+ {
+ return - r + l;
+ }
+
+ template <unsigned n>
+ void operator-=(intsub<n>& l, const intsub<n>& r)
+ {
+ l = l - r;
+ }
+
+ template <unsigned n>
+ void operator-=(intsub<n>& l, int r)
+ {
+ l = l - intsub<n>(r);
+ }
+
+ template <unsigned n>
+ intsub<n> operator*(const intsub<n>& l, const intsub<n>&
r)
+ {
+ return intsub<n>::make_from_enc_(l.to_enc() * r.to_enc() / n);
+ }
+
+ template <unsigned n>
+ intsub<n> operator*(const intsub<n>& l, int r)
+ {
+ return l * intsub<n>(r);
+ }
+
+ template <unsigned n>
+ intsub<n> operator*(int l, const intsub<n>& r)
+ {
+ return r * l;
+ }
+
+ template <unsigned n>
+ void operator*=(intsub<n>& l, const intsub<n>& r)
+ {
+ l = l * r;
+ }
+
+ template <unsigned n>
+ void operator*=(intsub<n>& l, int r)
+ {
+ l = l * intsub<n>(r);
+ }
+
+
+// other ops
+
+ template <unsigned n>
+ intsub<n> min(const intsub<n>& v1, const intsub<n>& v2)
+ {
+ return intsub<n>::make_from_enc_(v1.to_enc() < v2.to_enc() ? v1.to_enc() :
v2.to_enc());
+ }
+
+ template <unsigned n>
+ intsub<n> max(const intsub<n>& v1, const intsub<n>& v2)
+ {
+ return intsub<n>::make_from_enc_(v1.to_enc() > v2.to_enc() ? v1.to_enc() :
v2.to_enc());
+ }
+
+ template <unsigned n>
+ intsub<n> mean(const intsub<n>& v1, const intsub<n>& v2)
+ {
+ return intsub<n>::make_from_enc_((v1.to_enc() + v2.to_enc()) / 2);
+ }
+
+ template <unsigned n>
+ intsub<n> mean(const intsub<n>& v1, const intsub<n>& v2,
+ const intsub<n>& v3, const intsub<n>& v4)
+ {
+ return intsub<n>::make_from_enc_((v1.to_enc() + v2.to_enc()
+ + v3.to_enc() + v4.to_enc()) / 4);
+ }
+
+
+// <<
+
+ template <unsigned n>
+ std::ostream&
+ operator<<(std::ostream& ostr, const intsub<n>& i)
+ {
+ if (i.is_integer())
+ return ostr << i.to_int();
+ else
+ return ostr << floor(i).to_int() << ".5";
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+#endif // ! MLN_VALUE_INTSUB_HH
diff --git a/milena/mln/value/unsignedh.hh b/milena/mln/value/unsignedh.hh
deleted file mode 100644
index 1f0281c..0000000
--- a/milena/mln/value/unsignedh.hh
+++ /dev/null
@@ -1,415 +0,0 @@
-// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
-//
-// This file is part of Olena.
-//
-// Olena is free software: you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free
-// Software Foundation, version 2 of the License.
-//
-// Olena is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Olena. If not, see <http://www.gnu.org/licenses/>.
-//
-// As a special exception, you may use this file as part of a free
-// software project without restriction. Specifically, if other files
-// instantiate templates or use macros or inline functions from this
-// file, or you compile this file and link it with other files to produce
-// an executable, this file does not by itself cause the resulting
-// executable to be covered by the GNU General Public License. This
-// exception does not however invalidate any other reasons why the
-// executable file might be covered by the GNU General Public License.
-
-#ifndef MLN_VALUE_UNSIGNEDH_HH
-# define MLN_VALUE_UNSIGNEDH_HH
-
-/// \file
-///
-/// Define a semi-unsigned value class.
-
-# include <cstdlib>
-# include <iostream>
-# include <sstream>
-
-// FIXME: parameterize unsignedh so that we also can have
-// Z/4 and so on...
-
-namespace mln
-{
-
- namespace value
- {
-
-
- class unsignedh
- {
- public:
- unsignedh();
- unsignedh(const unsignedh& rhs);
- unsignedh(unsigned i);
- unsignedh(int i);
-
- unsignedh& operator=(const unsignedh& rhs);
- unsignedh& operator=(unsigned i);
- unsignedh& operator=(int i);
-
- unsigned enc() const;
-
- /// Construct an unsignedh with value v
- static unsignedh make(unsigned v);
- /// Construct an unsignedh with value v. The given value is
- /// rounded to the closest integer or half value.
-// static unsignedh make(float v);
-
- bool is_integer() const;
-
- unsigned to_unsigned() const;
-
- /// Set this unsignedh to its next value and return itself.
- unsignedh& goto_succ();
-
- /// Set this unsignedh to its previous value and return itself.
- unsignedh& goto_pred();
-
- operator std::string() const;
-
- private:
- unsigned enc_;
- };
-
-
- extern const unsignedh half;
-
-
-// next
-
- unsignedh succ(unsignedh i);
- unsignedh pred(unsignedh i);
-
-// rounding
-
- unsignedh floor(unsignedh i);
- unsignedh ceil(unsignedh i);
-
-
-// comparison
-
- bool operator==(unsignedh l, unsignedh r);
- bool operator<=(unsignedh l, unsignedh r);
- bool operator!=(unsignedh l, unsignedh r);
- bool operator>=(unsignedh l, unsignedh r);
- bool operator>(unsignedh l, unsignedh r);
- bool operator<(unsignedh l, unsignedh r);
-
-// arithmetics
-
- unsignedh operator+(unsignedh l, unsignedh r);
- void operator+=(unsignedh& l, unsignedh r);
- unsignedh operator-(unsignedh l, unsignedh r);
- void operator-=(unsignedh& l, unsignedh r);
- unsignedh operator/(unsignedh l, unsigned r);
-
-// other ops
-
- unsignedh min(unsignedh u1, unsignedh u2);
- unsignedh max(unsignedh u1, unsignedh u2);
- unsignedh mean(unsignedh u1, unsignedh u2);
-
-// for a transparent use of both unsigned and unsignedh
-// FIXME: is it useful?
-
- unsigned decode(unsigned u);
- void encode(unsigned u, unsigned& dst);
- unsigned decode(unsignedh u);
- void encode(unsigned u, unsignedh& dst);
-
-// <<
-
- std::ostream&
- operator<<(std::ostream& ostr, const unsignedh& i);
-
-
-# ifndef MLN_INCLUDE_ONLY
-
- inline
- unsignedh::unsignedh()
- {
- }
-
- inline
- unsignedh::unsignedh(const unsignedh& rhs)
- : enc_(rhs.enc_)
- {
- }
-
-
- inline
- unsignedh::unsignedh(unsigned i)
- {
- enc_ = 2 * i;
- }
-
- inline
- unsignedh::unsignedh(int i)
- {
- if (i < 0)
- std::abort();
- enc_ = 2 * i;
- }
-
- inline
- unsignedh&
- unsignedh::operator=(const unsignedh& rhs)
- {
- enc_ = rhs.enc_;
- return *this;
- }
-
- inline
- unsignedh&
- unsignedh::operator=(unsigned i)
- {
- enc_ = 2 * i;
- return *this;
- }
-
- inline
- unsignedh&
- unsignedh::operator=(int i)
- {
- if (i < 0)
- std::abort();
- enc_ = 2 * i;
- return *this;
- }
-
- inline
- unsigned
- unsignedh::enc() const
- {
- return enc_;
- }
-
- inline
- unsignedh unsignedh::make(unsigned enc)
- {
- unsignedh i;
- i.enc_ = enc;
- return i;
- }
-
- inline
- bool
- unsignedh::is_integer() const
- {
- return enc_ % 2 == 0;
- }
-
- inline
- unsigned
- unsignedh::to_unsigned() const
- {
- if (! this->is_integer())
- std::abort();
- return enc_ / 2;
- }
-
- inline
- unsignedh&
- unsignedh::goto_succ()
- {
- enc_ += 1;
- return *this;
- }
-
- inline
- unsignedh&
- unsignedh::goto_pred()
- {
- if (enc_ == 0)
- std::abort();
- enc_ -= 1;
- return *this;
- }
-
- inline
- unsignedh::operator std::string() const
- {
- std::stringstream s;
- s << *this;
- return s.str();
- }
-
-
-
-// half
-
-# ifndef MLN_WO_GLOBAL_VARS
-
- const unsignedh half = unsignedh::make(1u);
-
-# endif // ! MLN_WO_GLOBAL_VARS
-
-
-// next
-
- unsignedh succ(unsignedh i)
- {
- return unsignedh::make(i.enc() + 1);
- }
-
- unsignedh pred(unsignedh i)
- {
- if (i.enc() == 0)
- std::abort();
- return unsignedh::make(i.enc() - 1);
- }
-
-
-
-// rounding
-
- unsignedh floor(unsignedh i)
- {
- return i.is_integer() ? i : pred(i);
- }
-
- unsignedh ceil(unsignedh i)
- {
- return i.is_integer() ? i : succ(i);
- }
-
-
-
-// comparison
-
- bool operator==(unsignedh l, unsignedh r)
- {
- return l.enc() == r.enc();
- }
-
- bool operator<=(unsignedh l, unsignedh r)
- {
- return l.enc() <= r.enc();
- }
-
- bool operator!=(unsignedh l, unsignedh r)
- {
- return ! (l == r);
- }
-
- bool operator>=(unsignedh l, unsignedh r)
- {
- return r <= l;
- }
-
- bool operator>(unsignedh l, unsignedh r)
- {
- return ! (l <= r);
- }
-
- bool operator<(unsignedh l, unsignedh r)
- {
- return r > l;
- }
-
-
-
-// arithmetics
-
- unsignedh operator+(unsignedh l, unsignedh r)
- {
- return unsignedh::make(l.enc() + r.enc());
- }
-
- void operator+=(unsignedh& l, unsignedh r)
- {
- l = l + r;
- }
-
- unsignedh operator-(unsignedh l, unsignedh r)
- {
- if (r > l)
- std::abort();
- return unsignedh::make(l.enc() - r.enc());
- }
-
- void operator-=(unsignedh& l, unsignedh r)
- {
- if (r > l)
- std::abort();
- l = l - r;
- }
-
- unsignedh operator/(unsignedh l, unsigned r)
- {
- if (l.enc() % r != 0)
- std::abort();
- return unsignedh::make(l.enc() / r);
- }
-
-
-
-// other ops
-
- unsignedh min(unsignedh u1, unsignedh u2)
- {
- return unsignedh::make(u1.enc() < u2.enc() ? u1.enc() : u2.enc());
- }
-
- unsignedh max(unsignedh u1, unsignedh u2)
- {
- return unsignedh::make(u1.enc() > u2.enc() ? u1.enc() : u2.enc());
- }
-
- unsignedh mean(unsignedh u1, unsignedh u2)
- {
- return (u1 + u2) / 2;
- }
-
-
-// for a transparent use of both unsigned and unsignedh
-// FIXME: is it useful?
-
- unsigned decode(unsigned u)
- {
- return u;
- }
-
- void encode(unsigned u, unsigned& dst)
- {
- dst = u;
- }
-
- unsigned decode(unsignedh u)
- {
- return u.enc();
- }
-
- void encode(unsigned u, unsignedh& dst)
- {
- dst = unsignedh::make(u);
- }
-
-
-// <<
-
- std::ostream&
- operator<<(std::ostream& ostr, const unsignedh& i)
- {
- if (i.is_integer())
- return ostr << i.to_unsigned();
- else
- return ostr << floor(i).to_unsigned() << ".5";
- }
-
-# endif // ! MLN_INCLUDE_ONLY
-
- } // end of namespace mln::value
-
-} // end of namespace mln
-
-#endif // ndef UNSIGNEDH_HH
diff --git a/milena/tests/value/Makefile.am b/milena/tests/value/Makefile.am
index fb654fa..8d6718f 100644
--- a/milena/tests/value/Makefile.am
+++ b/milena/tests/value/Makefile.am
@@ -36,7 +36,7 @@ check_PROGRAMS = \
scalar \
set \
sign \
- unsignedh
+ intsub
# float01
# float01_bis
# float01_f
@@ -61,7 +61,7 @@ rgb8_SOURCES = rgb8.cc
scalar_SOURCES = scalar.cc
set_SOURCES = set.cc
sign_SOURCES = sign.cc
-unsignedh_SOURCES = unsignedh.cc
+intsub_SOURCES = intsub.cc
#<<lrde
# FIXME: Not distributed (yet).
diff --git a/milena/tests/value/unsignedh.cc b/milena/tests/value/intsub.cc
similarity index 65%
rename from milena/tests/value/unsignedh.cc
rename to milena/tests/value/intsub.cc
index ca98a59..e324fe3 100644
--- a/milena/tests/value/unsignedh.cc
+++ b/milena/tests/value/intsub.cc
@@ -26,19 +26,53 @@
/// \file
#include <cassert>
-#include <mln/value/unsignedh.hh>
-
+#include <mln/value/intsub.hh>
+#include <mln/value/inc.hh>
+#include <mln/value/dec.hh>
+#include <mln/value/succ.hh>
+#include <mln/value/prev.hh>
+#include <mln/math/mean.hh>
int main()
{
+ using namespace mln;
using namespace mln::value;
- unsignedh i = 2;
- i.goto_succ();
+ // i == 2
+ intsub<2> i = 2;
+ inc(i);
// i == 2.5
- assert(i == 2 + half);
+ mln_assertion(i == half + 2);
// (2.5 + 0.5) / 2 == 1.5
- assert(mean(i, half) == 1 + half);
+ mln_assertion(mean(i, half) == 1 + half);
+
+ // i == 3
+ inc(i);
+ mln_assertion(i == intsub<2>(3));
+
+ // i == 2.5
+ dec(i);
+ mln_assertion(i == intsub<2>(2,2));
+ dec(i);
+
+ // i == 2.5
+ mln_assertion(succ(i) == 2 + half);
+
+ // i == 1.5
+ mln_assertion(prev(i) == 2 - half);
+
+ // i == 6
+ i *= 3;
+ mln_assertion(i == 6);
+
+ // j = 6
+ intsub<4> j = i;
+ mln_assertion(j == 6);
+
+ // j = 6.25
+ inc(j);
+ mln_assertion(j == 6 + quarter);
+
}
--
1.7.2.5