last-svn-commit-593-g05e90bb Add conversions from int_u to float and double.

* mln/convert/from_to.hxx, * mln/value/int_u.hh: Here. --- milena/ChangeLog | 7 +++++++ milena/mln/convert/from_to.hxx | 11 ++++++++++- milena/mln/value/int_u.hh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 9cbc2db..d33bcc4 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,12 @@ 2010-11-15 Guillaume Lazzara <z@lrde.epita.fr> + Add conversions from int_u to float and double. + + * mln/convert/from_to.hxx, + * mln/value/int_u.hh: Here. + +2010-11-15 Guillaume Lazzara <z@lrde.epita.fr> + * mln/convert/from_to.hh: Make use of value::cast for conversions between built-in types. diff --git a/milena/mln/convert/from_to.hxx b/milena/mln/convert/from_to.hxx index f4f690d..24f974a 100644 --- a/milena/mln/convert/from_to.hxx +++ b/milena/mln/convert/from_to.hxx @@ -1,4 +1,5 @@ -// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2008, 2009, 2010 EPITA Research and Development +// Laboratory (LRDE) // // This file is part of Olena. // @@ -202,6 +203,14 @@ namespace mln void from_to_(const value::int_u<n>& from, bool& to_); + // int_u -> float + template <unsigned n> + void from_to_(const value::int_u<n>& from, float& to_); + + // int_u -> double + template <unsigned n> + void from_to_(const value::int_u<n>& from, double& to_); + // label -> int_u. template <unsigned n> void diff --git a/milena/mln/value/int_u.hh b/milena/mln/value/int_u.hh index 9bf40ff..f3786f9 100644 --- a/milena/mln/value/int_u.hh +++ b/milena/mln/value/int_u.hh @@ -128,6 +128,18 @@ namespace mln from_to_(const value::int_u<n>& from, bool& to_); + // int_u -> float. + template <unsigned n> + void + from_to_(const value::int_u<n>& from, float& to_); + + + // int_u -> double. + template <unsigned n> + void + from_to_(const value::int_u<n>& from, double& to_); + + } // end of namespace mln::convert::over_load } // end of namespace mln::convert @@ -232,6 +244,24 @@ namespace mln to_ = (from != 0u); } + // int_u -> float. + template <unsigned n> + inline + void + from_to_(const value::int_u<n>& from, float& to_) + { + to_ = static_cast<float>(from); + } + + // int_u -> double. + template <unsigned n> + inline + void + from_to_(const value::int_u<n>& from, double& to_) + { + to_ = static_cast<double>(from); + } + } // end of namespace mln::convert::over_load -- 1.5.6.5
participants (1)
-
Guillaume Lazzara