floatings.hh 3.44 KB
Newer Older
1
2
// Copyright (C) 2007, 2008, 2009, 2011 EPITA Research and Development
// Laboratory (LRDE)
3
//
4
// This file is part of Olena.
5
//
6
7
8
9
10
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
11
12
13
14
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// 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
22
23
24
25
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License.  This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
26
27
28
29

#ifndef MLN_VALUE_BUILTIN_FLOATINGS_HH
# define MLN_VALUE_BUILTIN_FLOATINGS_HH

30
/// \file
Guillaume Lazzara's avatar
Guillaume Lazzara committed
31
32
///
/// Some definitions about built-in floating types.
33

Guillaume Lazzara's avatar
Guillaume Lazzara committed
34
# include <mln/value/internal/limits.hh>
35

36
37
38
39
40
41
42
43
44
45
46
47
# include <mln/value/concept/built_in.hh>
# include <mln/value/concept/floating.hh>
# include <mln/trait/value_.hh>


namespace mln
{


  template <>
  struct category< float >
  {
Thierry Geraud's avatar
Thierry Geraud committed
48
    typedef value::Built_In< value::Floating<void> > ret;
49
50
51
52
53
  };

  template <>
  struct category< double >
  {
Thierry Geraud's avatar
Thierry Geraud committed
54
    typedef value::Built_In< value::Floating<void> > ret;
55
56
57
58
59
60
  };


  namespace trait
  {

61
62
63

    // float.

64
65
66
    template <>
    struct value_< float >
    {
67
      enum {
68
	dim   = 1,
69
70
71
72
73
74
75
76
	nbits = 8 * sizeof(float),
	card  = 0
      };

      typedef value::nature::floating nature;
      typedef value::kind::data       kind;
      typedef value::quant::high      quant;

77
      static float min()
78
      {
Guillaume Lazzara's avatar
Guillaume Lazzara committed
79
	static const float min_ = mln::value::internal::limits<float>::min();
80
81
	return min_;
      }
82
      static float max()
83
      {
Guillaume Lazzara's avatar
Guillaume Lazzara committed
84
	static const float max_ = mln::value::internal::limits<float>::max();
85
86
	return max_;
      }
87
      static float epsilon()
88
      {
Guillaume Lazzara's avatar
Guillaume Lazzara committed
89
	static const float epsilon_ = mln::value::internal::limits<float>::epsilon();
90
91
92
	return epsilon_;
      }

93
      typedef float                        sum;
94
95
96
97

      static const char* name()
      { return "float"; }

98
99
    };

100
101
102

    // double.

103
104
105
    template <>
    struct value_< double >
    {
106
      enum {
107
	dim   = 1,
108
109
110
111
112
113
114
115
	nbits = 8 * sizeof(double),
	card  = 0
      };

      typedef value::nature::floating nature;
      typedef value::kind::data       kind;
      typedef value::quant::high      quant;

116
      static double min()
117
      {
Guillaume Lazzara's avatar
Guillaume Lazzara committed
118
	static const double min_ = mln::value::internal::limits<double>::min();
119
120
	return min_;
      }
121
      static double max()
122
      {
Guillaume Lazzara's avatar
Guillaume Lazzara committed
123
	static const double max_ = mln::value::internal::limits<double>::max();
124
125
	return max_;
      }
126
      static double epsilon()
127
      {
Guillaume Lazzara's avatar
Guillaume Lazzara committed
128
	static const double epsilon_ = mln::value::internal::limits<double>::epsilon();
129
130
131
	return epsilon_;
      }

132
      typedef double                        sum;
133
134

      static const char* name()
135
      { return "double"; }
136

137
138
139
140
141
142
143
144
    };

  } // end of namespace mln::trait

} // end of namespace mln


#endif // ! MLN_VALUE_BUILTIN_FLOATINGS_HH