$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
floatings.hh
1 // Copyright (C) 2007, 2008, 2009, 2011 EPITA Research and Development
2 // Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_VALUE_BUILTIN_FLOATINGS_HH
28 # define MLN_VALUE_BUILTIN_FLOATINGS_HH
29 
33 
34 # include <mln/value/internal/limits.hh>
35 
36 # include <mln/value/concept/built_in.hh>
37 # include <mln/value/concept/floating.hh>
38 # include <mln/trait/value_.hh>
39 
40 
41 namespace mln
42 {
43 
44 
45  template <>
46  struct category< float >
47  {
48  typedef value::Built_In< value::Floating<void> > ret;
49  };
50 
51  template <>
52  struct category< double >
53  {
54  typedef value::Built_In< value::Floating<void> > ret;
55  };
56 
57 
58  namespace trait
59  {
60 
61 
62  // float.
63 
64  template <>
65  struct value_< float >
66  {
67  enum {
68  dim = 1,
69  nbits = 8 * sizeof(float),
70  card = 0
71  };
72 
73  typedef value::nature::floating nature;
74  typedef value::kind::data kind;
75  typedef value::quant::high quant;
76 
77  static float min()
78  {
79  // NOTE: limits<float>::min() returns the minimum positive
80  // value. However, in Milena, min() means the minimum value of the
81  // possible range value, i.e., the lowest negative
82  // value. Since float has a symetric range value, we can
83  // safely use -MAX.
84  static const float min_ = - mln::value::internal::limits<float>::max();
85  return min_;
86  }
87  static float max()
88  {
89  static const float max_ = mln::value::internal::limits<float>::max();
90  return max_;
91  }
92  static float epsilon()
93  {
94  static const float epsilon_ = mln::value::internal::limits<float>::epsilon();
95  return epsilon_;
96  }
97 
98  typedef float sum;
99 
100  static const char* name()
101  { return "float"; }
102 
103  };
104 
105 
106  // double.
107 
108  template <>
109  struct value_< double >
110  {
111  enum {
112  dim = 1,
113  nbits = 8 * sizeof(double),
114  card = 0
115  };
116 
117  typedef value::nature::floating nature;
118  typedef value::kind::data kind;
119  typedef value::quant::high quant;
120 
121  static double min()
122  {
123  // NOTE: limits<double>::min() returns the minimum positive
124  // value. However, in Milena, min() means the minimum value of
125  // the possible range value, i.e., the lowest negative
126  // value. Since double has a symetric range value, we can
127  // safely use -MAX.
128  static const double min_ = - mln::value::internal::limits<double>::max();
129  return min_;
130  }
131  static double max()
132  {
133  static const double max_ = mln::value::internal::limits<double>::max();
134  return max_;
135  }
136  static double epsilon()
137  {
138  static const double epsilon_ = mln::value::internal::limits<double>::epsilon();
139  return epsilon_;
140  }
141 
142  typedef double sum;
143 
144  static const char* name()
145  { return "double"; }
146 
147  };
148 
149  } // end of namespace mln::trait
150 
151 } // end of namespace mln
152 
153 
154 #endif // ! MLN_VALUE_BUILTIN_FLOATINGS_HH