Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009, 2011 EPITA Research and Development 00002 // 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_BUILTIN_FLOATINGS_HH 00028 # define MLN_VALUE_BUILTIN_FLOATINGS_HH 00029 00033 00034 # include <mln/value/internal/limits.hh> 00035 00036 # include <mln/value/concept/built_in.hh> 00037 # include <mln/value/concept/floating.hh> 00038 # include <mln/trait/value_.hh> 00039 00040 00041 namespace mln 00042 { 00043 00044 00045 template <> 00046 struct category< float > 00047 { 00048 typedef value::Built_In< value::Floating<void> > ret; 00049 }; 00050 00051 template <> 00052 struct category< double > 00053 { 00054 typedef value::Built_In< value::Floating<void> > ret; 00055 }; 00056 00057 00058 namespace trait 00059 { 00060 00061 00062 // float. 00063 00064 template <> 00065 struct value_< float > 00066 { 00067 enum { 00068 dim = 1, 00069 nbits = 8 * sizeof(float), 00070 card = 0 00071 }; 00072 00073 typedef value::nature::floating nature; 00074 typedef value::kind::data kind; 00075 typedef value::quant::high quant; 00076 00077 static float min() 00078 { 00079 // NOTE: limits<float>::min() returns the minimum positive 00080 // value. However, in Milena, min() means the minimum value of the 00081 // possible range value, i.e., the lowest negative 00082 // value. Since float has a symetric range value, we can 00083 // safely use -MAX. 00084 static const float min_ = - mln::value::internal::limits<float>::max(); 00085 return min_; 00086 } 00087 static float max() 00088 { 00089 static const float max_ = mln::value::internal::limits<float>::max(); 00090 return max_; 00091 } 00092 static float epsilon() 00093 { 00094 static const float epsilon_ = mln::value::internal::limits<float>::epsilon(); 00095 return epsilon_; 00096 } 00097 00098 typedef float sum; 00099 00100 static const char* name() 00101 { return "float"; } 00102 00103 }; 00104 00105 00106 // double. 00107 00108 template <> 00109 struct value_< double > 00110 { 00111 enum { 00112 dim = 1, 00113 nbits = 8 * sizeof(double), 00114 card = 0 00115 }; 00116 00117 typedef value::nature::floating nature; 00118 typedef value::kind::data kind; 00119 typedef value::quant::high quant; 00120 00121 static double min() 00122 { 00123 // NOTE: limits<double>::min() returns the minimum positive 00124 // value. However, in Milena, min() means the minimum value of 00125 // the possible range value, i.e., the lowest negative 00126 // value. Since double has a symetric range value, we can 00127 // safely use -MAX. 00128 static const double min_ = - mln::value::internal::limits<double>::max(); 00129 return min_; 00130 } 00131 static double max() 00132 { 00133 static const double max_ = mln::value::internal::limits<double>::max(); 00134 return max_; 00135 } 00136 static double epsilon() 00137 { 00138 static const double epsilon_ = mln::value::internal::limits<double>::epsilon(); 00139 return epsilon_; 00140 } 00141 00142 typedef double sum; 00143 00144 static const char* name() 00145 { return "double"; } 00146 00147 }; 00148 00149 } // end of namespace mln::trait 00150 00151 } // end of namespace mln 00152 00153 00154 #endif // ! MLN_VALUE_BUILTIN_FLOATINGS_HH