26 #ifndef MLN_VALUE_FLOAT01__HH
27 # define MLN_VALUE_FLOAT01__HH
35 # include <mln/core/contract.hh>
36 # include <mln/metal/math/pow.hh>
37 # include <mln/metal/bexpr.hh>
39 # include <mln/value/int_u.hh>
40 # include <mln/value/concept/floating.hh>
41 # include <mln/value/internal/convert.hh>
42 # include <mln/value/float01.hh>
43 # include <mln/trait/value_.hh>
53 template <
unsigned n>
struct float01_;
61 struct value_< mln::value::float01_<n> >
66 card = mln_value_card_from_(nbits)
69 typedef trait::value::nature::floating
nature;
70 typedef trait::value::kind::data
kind;
71 typedef mln_value_quant_from_(card) quant;
73 static
float min() {
return 0.f; }
74 static float max() {
return 1.f; }
75 static float epsilon() {
return 0.f; }
119 void set_ind(
unsigned long val);
122 operator float()
const;
132 template <
unsigned n>
151 template <
unsigned n>
152 std::ostream& operator<<(std::ostream& ostr, const float01_<n>& f);
155 template <
unsigned n,
unsigned m>
158 template <
unsigned n>
163 # ifndef MLN_INCLUDE_ONLY
167 template <
unsigned n>
173 template <
unsigned n>
177 mln_precondition(val >= 0.f);
178 mln_precondition(val <= 1.f);
179 this->v_ =
static_cast<enc_
>(val * (
float(mln_max(enc_)) - 1.f));
182 template <
unsigned n>
187 return float(this->v_) / (
float(mln_max(enc_)) - 1.f);
190 template <
unsigned n>
195 this->v_ =
static_cast<enc_
>(val);
198 template <
unsigned n>
205 template <
unsigned n>
214 template <
unsigned n>
221 template <
unsigned n>
230 template <
unsigned n>
235 mln_precondition(val >= 0.f);
236 mln_precondition(val <= 1.f);
237 this->v_ =
static_cast<enc_
>(val * (
float(mln_max(enc_)) - 1.f));
241 template <
unsigned n>
243 float01_<n>::operator
float()
const
245 return float(this->v_) / (
float(mln_max(enc_)) - 1.f);
251 template <
unsigned n>
253 std::ostream& operator<<(std::ostream& ostr, const float01_<n>& f)
255 return ostr << f.value();
258 template <
unsigned n,
unsigned m>
262 return float01(lhs) == float01(rhs);
265 template <
unsigned n>
269 return float01(lhs) == float01_<n>(f);
273 # endif // ! MLN_INCLUDE_ONLY
279 #endif // ! MLN_VALUE_FLOAT01__HH