• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

float01.cc

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #include <iostream>
00027 
00028 #include <mln/core/concept/function.hh>
00029 #include <mln/value/float01_8.hh>
00030 #include <mln/value/float01_16.hh>
00031 #include <mln/value/int_u8.hh>
00032 
00033 
00034 namespace mln
00035 {
00036 
00037   using namespace value;
00038 
00039   float fi(int) { return 0.5f; }
00040   int ii(int) { return 1; }
00041 
00042   float fd(double) { return 0.5f; }
00043   int id(double) { return 1; }
00044 
00045 
00046   struct tofloat01 : Function_v2v<tofloat01>
00047   {
00048 
00049     typedef float01_<12> result;
00050     result operator()(int_u8 v) const
00051     {
00052       result ret = static_cast<float>(v) / static_cast<float>(mln_max(int_u8));
00053       //    std::cout << v << "-> "  << ret << std::endl;
00054       return ret;
00055     }
00056   };
00057 
00058   struct to8bits : Function_v2v<to8bits>
00059   {
00060 
00061     typedef int_u8 result;
00062     result operator()(float01_<12> v) const
00063     {
00064       result ret = static_cast<int>(v.value() * 255);
00065       // FIXME: Dead code.
00066       //std::cout << v << "-> " << ret << std::endl;
00067       return ret;
00068     }
00069   };
00070 
00071 } // mln
00072 
00073 
00074 int main()
00075 {
00076   using namespace mln;
00077   
00078   value::float01_8  a(0.5);
00079   value::float01_16 b(0.5);
00080 
00081   mln_assertion(approx_equal(b,a));
00082 
00083   std::cout << b << std::endl;
00084   b = b + 0.2f;
00085   std::cout << b << std::endl;
00086   b = b - 0.2f;
00087   std::cout << b << std::endl;
00088   b = b * 1.5f;
00089   std::cout << b << std::endl;
00090   b = b / 4.6f;
00091   std::cout << b << std::endl;
00092 
00093   b = b / 3;
00094   std::cout << b << std::endl;
00095   b = b * 1;
00096   std::cout << b << std::endl;
00097 
00098   a = fi( static_cast<int>(a) );
00099   a = static_cast<float>( ii( static_cast<int>(a) ) );
00100   a = fd(a);
00101   a = static_cast<float>( id(a) );
00102 
00103   b = a;
00104   a = b;
00105   b = 0.34f;
00106   std::cout << b << std::endl;
00107   b = 0;
00108   std::cout << b << std::endl;
00109   b = 1;
00110   std::cout << b << std::endl;
00111 }

Generated on Tue Oct 4 2011 15:23:47 for Milena (Olena) by  doxygen 1.7.1