1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
/* Specializations of std::numeric_limits for "checked" types.
Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
Copyright (C) 2010-2011 BUGSENG srl (http://bugseng.com)
This file is part of the Parma Polyhedra Library (PPL).
The PPL 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; either version 3 of the License, or (at your
option) any later version.
The PPL is distributed in the hope that it will be useful, 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
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
For the most up-to-date information see the Parma Polyhedra Library
site: http://www.cs.unipr.it/ppl/ . */
#ifndef PPL_checked_numeric_limits_hh
#define PPL_checked_numeric_limits_hh 1
#include "Checked_Number.defs.hh"
#include "checked_int.inlines.hh"
#include <limits>
namespace std {
using namespace Parma_Polyhedra_Library;
#define PPL_SPECIALIZE_LIMITS_INT(T) \
/*! \brief Partial specialization of std::numeric_limits. */ \
template <typename Policy> \
class numeric_limits<Checked_Number<T, Policy> > \
: public numeric_limits<T> { \
private: \
typedef Checked_Number<T, Policy> Type; \
\
public: \
static const bool has_infinity = Policy::has_infinity; \
static const bool has_quiet_NaN = Policy::has_nan; \
\
static Type min() { \
Type v; \
v.raw_value() = Checked::Extended_Int<Policy, T>::min; \
return v; \
} \
\
static Type max() { \
Type v; \
v.raw_value() = Checked::Extended_Int<Policy, T>::max; \
return v; \
} \
\
static Type infinity() { \
Type v; \
Checked::assign_special<Policy>(v.raw_value(), VC_PLUS_INFINITY, \
ROUND_IGNORE); \
return v; \
} \
\
static Type quiet_NaN() { \
Type v; \
Checked::assign_special<Policy>(v.raw_value(), VC_NAN, \
ROUND_IGNORE); \
return v; \
} \
};
PPL_SPECIALIZE_LIMITS_INT(char)
PPL_SPECIALIZE_LIMITS_INT(signed char)
PPL_SPECIALIZE_LIMITS_INT(signed short)
PPL_SPECIALIZE_LIMITS_INT(signed int)
PPL_SPECIALIZE_LIMITS_INT(signed long)
PPL_SPECIALIZE_LIMITS_INT(signed long long)
PPL_SPECIALIZE_LIMITS_INT(unsigned char)
PPL_SPECIALIZE_LIMITS_INT(unsigned short)
PPL_SPECIALIZE_LIMITS_INT(unsigned int)
PPL_SPECIALIZE_LIMITS_INT(unsigned long)
PPL_SPECIALIZE_LIMITS_INT(unsigned long long)
#undef PPL_SPECIALIZE_LIMITS_INT
#define PPL_SPECIALIZE_LIMITS_FLOAT(T) \
/*! \brief Partial specialization of std::numeric_limits. */ \
template <typename Policy> \
struct numeric_limits<Checked_Number<T, Policy> > \
: public numeric_limits<T> { \
};
#if PPL_SUPPORTED_FLOAT
PPL_SPECIALIZE_LIMITS_FLOAT(float)
#endif
#if PPL_SUPPORTED_DOUBLE
PPL_SPECIALIZE_LIMITS_FLOAT(double)
#endif
#if PPL_SUPPORTED_LONG_DOUBLE
PPL_SPECIALIZE_LIMITS_FLOAT(long double)
#endif
#undef PPL_SPECIALIZE_LIMITS_FLOAT
#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
//! Partial specialization of std::numeric_limits.
#endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
template <typename Policy>
class
numeric_limits<Checked_Number<mpz_class, Policy> >
: public numeric_limits<mpz_class> {
private:
typedef Checked_Number<mpz_class, Policy> Type;
public:
static const bool has_infinity = Policy::has_infinity;
static const bool has_quiet_NaN = Policy::has_nan;
static Type infinity() {
Type v;
Checked::assign_special<Policy>(v.raw_value(), VC_PLUS_INFINITY,
ROUND_IGNORE);
return v;
}
static Type quiet_NaN() {
Type v;
Checked::assign_special<Policy>(v.raw_value(), VC_NAN, ROUND_IGNORE);
return v;
}
};
#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
//! Partial specialization of std::numeric_limits.
#endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
template <typename Policy>
class
numeric_limits<Checked_Number<mpq_class, Policy> >
: public numeric_limits<mpq_class> {
private:
typedef Checked_Number<mpq_class, Policy> Type;
public:
static const bool has_infinity = Policy::has_infinity;
static const bool has_quiet_NaN = Policy::has_nan;
static Type infinity() {
Type v;
Checked::assign_special<Policy>(v.raw_value(), VC_PLUS_INFINITY,
ROUND_IGNORE);
return v;
}
static Type quiet_NaN() {
Type v;
Checked::assign_special<Policy>(v.raw_value(), VC_NAN, ROUND_IGNORE);
return v;
}
};
} // namespace std
#endif // !defined(PPL_checked_numeric_limits_hh)
|