27 #ifndef MLN_VALUE_INTERNAL_GRAY_F_HH
28 # define MLN_VALUE_INTERNAL_GRAY_F_HH
37 # include <mln/value/ops.hh>
39 # include <mln/core/contract.hh>
40 # include <mln/metal/math/pow.hh>
41 # include <mln/metal/bexpr.hh>
42 # include <mln/literal/ops.hh>
44 # include <mln/value/float01_f.hh>
45 # include <mln/trait/value_.hh>
47 # include <mln/value/graylevel_f.hh>
65 template <
unsigned n>
class gray_;
79 template <
template <
class,
class>
class Name>
80 struct set_precise_binary_< Name, mln::value::internal::gray_f, mln::value::internal::gray_f >
82 typedef mln::value::internal::gray_f ret;
86 struct set_precise_binary_< op::greater, mln::value::internal::gray_f, mln::value::internal::gray_f >
92 struct set_precise_binary_< op::eq, mln::value::internal::gray_f, mln::value::internal::gray_f >
107 template <
typename T>
struct value_;
111 struct value_<mln::value::internal::gray_f>
114 typedef mln::value::internal::gray_f self_;
115 typedef float equiv_;
120 nbits = mln_nbits(equiv_),
124 typedef trait::value::nature::floating nature;
125 typedef trait::value::kind::gray kind;
126 typedef mln_trait_value_quant_(equiv_) quant;
128 static equiv_ min() {
return 0; }
129 static equiv_
max() {
return 1; }
130 static equiv_ epsilon() {
return mln_epsilon(equiv_); }
148 public Floating< gray_f >,
150 public internal::value_like_< float,
159 gray_f(
const gray_f& rhs);
160 gray_f& operator=(
const gray_f& rhs);
164 template <
unsigned n>
165 gray_f(
const gray_<n>& rhs);
166 template <
unsigned n>
167 gray_f& operator=(
const gray_<n>& rhs);
172 gray_f& operator=(
float val);
176 gray_f(
const graylevel_f& val);
177 gray_f& operator=(
const graylevel_f& val);
181 template <
unsigned m>
182 operator graylevel<m>()
const;
185 template <
unsigned m>
186 operator gray_<m>()
const;
189 operator graylevel_f()
const;
198 std::ostream& operator<<(std::ostream& ostr,
const gray_f& g);
207 # include <mln/value/internal/gray_.hh>
219 # ifndef MLN_INCLUDE_ONLY
229 gray_f::gray_f(
const gray_f& g)
237 gray_f::operator=(
const gray_f& g)
243 template <
unsigned n>
244 gray_f::gray_f(
const gray_<n>& rhs)
246 static const float denom = float(metal::math::pow_int<2, n>::value) - 1.f;
247 this->v_ = float(rhs.value()) / denom;
250 template <
unsigned n>
252 gray_f::operator=(
const gray_<n>& rhs)
254 static const float denom = float(metal::math::pow_int<2, n>::value) - 1.f;
255 this->v_ = float(rhs.value()) / denom;
260 gray_f::gray_f(
float val)
267 gray_f::operator=(
float val)
274 gray_f::gray_f(
const graylevel_f& rhs)
276 this->v_ = rhs.value();
281 gray_f::operator=(
const graylevel_f& rhs)
283 this->v_ = rhs.value();
287 template <
unsigned m>
289 gray_f::operator graylevel<m>()
const
291 return graylevel<m>(int(round(this->v_ * (mlc_pow_int(2, m) - 1))));
295 template <
unsigned m>
297 gray_f::operator gray_<m>()
const
299 return gray_<m>(int(round(this->v_ * (mlc_pow_int(2, m) - 1))));
303 gray_f::operator graylevel_f()
const
305 return graylevel_f(this->v_);
310 gray_f::value()
const
318 std::ostream& operator<<(std::ostream& ostr,
const gray_f& g)
320 return ostr << g.value() <<
"/gl_f";
323 # endif // ! MLN_INCLUDE_ONLY
332 template <
typename I>
335 operator==(
const Integer<I>& lhs,
const graylevel_f& rhs)
337 return rhs.value() == exact(lhs);
343 operator==(
const graylevel_f& lhs,
const graylevel_f& rhs)
345 return rhs.value() == lhs.value();
350 mln_trait_op_plus_(graylevel_f, graylevel_f)
351 operator+(const graylevel_f& lhs, const graylevel_f& rhs)
353 return lhs.value() + rhs.value();
357 template <
unsigned n>
359 mln_trait_op_plus(graylevel_f, graylevel<n>)
360 operator+(const graylevel_f& lhs, const graylevel<n>& rhs)
362 return lhs.value() + graylevel_f(rhs).value();
366 template <
unsigned n>
368 mln_trait_op_plus(graylevel_f, graylevel<n>)
369 operator+(const graylevel<n>& lhs, const graylevel_f& rhs)
371 return rhs.value() + graylevel_f(lhs).value();
376 template <
typename I>
379 operator+(
const graylevel_f& lhs,
const I& i)
383 typename Object<I>::wrong_use_of_graylevel_f___Please_use_the__to_enc__method a;
388 template <
typename I>
391 operator+(
const I& i,
const graylevel_f& rhs)
395 typename Object<I>::wrong_use_of_graylevel_f___Please_use_the__to_enc__method a;
400 template <
typename I>
403 operator-(
const graylevel_f& lhs,
const I& i)
407 typename Object<I>::wrong_use_of_graylevel_f___Please_use_the__to_enc__method a;
412 template <
typename I>
415 operator-(
const I& i,
const graylevel_f& rhs)
419 typename Object<I>::wrong_use_of_graylevel_f___Please_use_the__to_enc__method a;
425 mln_trait_op_minus_(graylevel_f, graylevel_f)
426 operator-(const graylevel_f& lhs, const graylevel_f& rhs)
428 return lhs.value() - rhs.value();
433 mln_trait_op_times_(graylevel_f, graylevel_f)
434 operator*(const graylevel_f& lhs, const graylevel_f& rhs)
436 return lhs.value() * rhs.value();
441 template <
typename I>
443 mln_trait_op_times(graylevel_f, I)
444 operator*(const graylevel_f& lhs, const Integer<I>& rhs)
446 return lhs.value() * int(exact(rhs));
449 template <
typename I>
451 mln_trait_op_times(I, graylevel_f)
452 operator*(const Integer<I>& lhs, const graylevel_f& rhs)
454 return rhs.value() * int(exact(lhs));
459 template <
typename F>
461 mln_trait_op_times(graylevel_f, F)
462 operator*(const graylevel_f& lhs, const Floating<F>& rhs)
464 return lhs.value() * exact(rhs);
467 template <
typename F>
469 mln_trait_op_times(F, graylevel_f)
470 operator*(const Floating<F>& lhs, const graylevel_f& rhs)
472 return rhs.value() * exact(lhs);
478 template <
typename S>
480 mln_trait_op_times(graylevel_f, S)
481 operator*(const graylevel_f& lhs, const scalar_<S>& rhs)
483 return lhs.value() * rhs.to_equiv();
487 template <
typename S>
489 mln_trait_op_div(graylevel_f, S)
490 operator/(const graylevel_f& lhs, const scalar_<S>& rhs)
492 mln_precondition(rhs.to_equiv() != S(0));
493 return lhs.value() / rhs.to_equiv();
500 #endif // ! MLN_VALUE_INTERNAL_GRAY_F_HH