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

float01_f.hh

00001 // Copyright (C) 2006, 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 #ifndef MLN_VALUE_FLOAT01_F_HH
00027 # define MLN_VALUE_FLOAT01_F_HH
00028 
00034 # include <iostream>
00035 # include <mln/value/internal/value_like.hh>
00036 # include <mln/value/concept/floating.hh>
00037 # include <mln/value/builtin/floatings.hh>
00038 # include <mln/trait/value_.hh>
00039 
00040 
00041 namespace mln
00042 {
00043 
00044   // Fwd decls.
00045   namespace value {
00046     struct float01;
00047     struct float01_f;
00048   }
00049 
00050 
00051   namespace trait
00052   {
00053 
00054     template <>
00055     struct value_< mln::value::float01_f >
00056     {
00057       typedef trait::value::nature::floating nature;
00058       typedef trait::value::kind::data       kind;
00059       typedef trait::value::quant::high      quant;
00060 
00061       enum {
00062         dim = 1,
00063         nbits = 8 * sizeof(float),
00064         card  = 0
00065       };
00066 
00067       static float min() { return 0; }
00068       static float max() { return 1; }
00069       static float epsilon() { return mln_epsilon(float); }
00070 
00071       typedef float comp;
00072 
00073       typedef float sum;
00074     };
00075 
00076   } // end of namespace trait
00077 
00078 
00079 
00080   namespace value
00081   {
00082 
00084     struct float01_f
00085       :
00086       public Floating< float01_f >,
00087 
00088       public internal::value_like_< float,      // Equivalent.
00089                                     float,      // Encoding.
00090                                     float,      // Interoperation.
00091                                     float01_f > // Exact.
00092     {
00094       float01_f();
00095 
00097       float01_f(float val);
00098 
00100       float01_f& operator=(const float val);
00101 
00103       float value() const;
00104 
00106       operator float() const;
00107     };
00108 
00109 
00110 # ifndef MLN_INCLUDE_ONLY
00111 
00112     // Float01_F.
00113 
00114     inline
00115     float01_f::float01_f()
00116     {
00117     }
00118 
00119     inline
00120     float01_f::float01_f(float val)
00121     {
00122       mln_precondition(val >= 0);
00123       mln_precondition(val <= 1);
00124       this->v_ = val;
00125     }
00126 
00127     inline
00128     float
00129     float01_f::value() const
00130     {
00131       return this->v_;
00132     }
00133 
00134     inline
00135     float01_f&
00136     float01_f::operator=(float val)
00137     {
00138       mln_precondition(val >= 0);
00139       mln_precondition(val <= 1);
00140       this->v_ = val;
00141       return *this;
00142     }
00143 
00144     inline
00145     float01_f::operator float() const
00146     {
00147       return this->v_;
00148     }
00149 
00150 # endif // ! MLN_INCLUDE_ONLY
00151 
00152   } // end of namespace mln::value
00153 
00154 } // end of namespace mln
00155 
00156 
00157 #endif // ! MLN_VALUE_FLOAT01_F_HH

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