00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
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       
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       
00066       
00067       return ret;
00068     }
00069   };
00070 
00071 } 
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 }