Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2006, 2007, 2008, 2009, 2011 EPITA Research and 00002 // Development Laboratory (LRDE) 00003 // 00004 // This file is part of Olena. 00005 // 00006 // Olena is free software: you can redistribute it and/or modify it under 00007 // the terms of the GNU General Public License as published by the Free 00008 // Software Foundation, version 2 of the License. 00009 // 00010 // Olena is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software project without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to produce 00022 // an executable, this file does not by itself cause the resulting 00023 // executable to be covered by the GNU General Public License. This 00024 // exception does not however invalidate any other reasons why the 00025 // executable file might be covered by the GNU General Public License. 00026 00027 #ifndef MLN_VALUE_FLOAT01_F_HH 00028 # define MLN_VALUE_FLOAT01_F_HH 00029 00035 # include <iostream> 00036 # include <mln/value/internal/value_like.hh> 00037 # include <mln/value/concept/floating.hh> 00038 # include <mln/value/builtin/floatings.hh> 00039 # include <mln/trait/value_.hh> 00040 00041 00042 namespace mln 00043 { 00044 00045 // Fwd decls. 00046 namespace value { 00047 class float01; 00048 struct float01_f; 00049 } 00050 00051 00052 namespace trait 00053 { 00054 00055 template <> 00056 struct value_< mln::value::float01_f > 00057 { 00058 typedef trait::value::nature::floating nature; 00059 typedef trait::value::kind::data kind; 00060 typedef trait::value::quant::high quant; 00061 00062 enum { 00063 dim = 1, 00064 nbits = 8 * sizeof(float), 00065 card = 0 00066 }; 00067 00068 static float min() { return 0; } 00069 static float max() { return 1; } 00070 static float epsilon() { return mln_epsilon(float); } 00071 00072 typedef float comp; 00073 00074 typedef float sum; 00075 }; 00076 00077 } // end of namespace trait 00078 00079 00080 00081 namespace value 00082 { 00083 00085 struct float01_f 00086 : 00087 public Floating< float01_f >, 00088 00089 public internal::value_like_< float, // Equivalent. 00090 float, // Encoding. 00091 float, // Interoperation. 00092 float01_f > // Exact. 00093 { 00095 float01_f(); 00096 00098 float01_f(float val); 00099 00101 float01_f& operator=(const float val); 00102 00104 float value() const; 00105 00107 operator float() const; 00108 }; 00109 00110 00111 # ifndef MLN_INCLUDE_ONLY 00112 00113 // Float01_F. 00114 00115 inline 00116 float01_f::float01_f() 00117 { 00118 } 00119 00120 inline 00121 float01_f::float01_f(float val) 00122 { 00123 mln_precondition(val >= 0); 00124 mln_precondition(val <= 1); 00125 this->v_ = val; 00126 } 00127 00128 inline 00129 float 00130 float01_f::value() const 00131 { 00132 return this->v_; 00133 } 00134 00135 inline 00136 float01_f& 00137 float01_f::operator=(float val) 00138 { 00139 mln_precondition(val >= 0); 00140 mln_precondition(val <= 1); 00141 this->v_ = val; 00142 return *this; 00143 } 00144 00145 inline 00146 float01_f::operator float() const 00147 { 00148 return this->v_; 00149 } 00150 00151 # endif // ! MLN_INCLUDE_ONLY 00152 00153 } // end of namespace mln::value 00154 00155 } // end of namespace mln 00156 00157 00158 #endif // ! MLN_VALUE_FLOAT01_F_HH