p1788 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +8 -0
- data/AUTHORS +6 -0
- data/LICENSE +201 -0
- data/NOTICE +29 -0
- data/README.md +65 -0
- data/ext/libieeep1788_copy/README +3 -0
- data/ext/libieeep1788_copy/p1788/AUTHORS +16 -0
- data/ext/libieeep1788_copy/p1788/LICENSE +202 -0
- data/ext/libieeep1788_copy/p1788/NOTICE +14 -0
- data/ext/libieeep1788_copy/p1788/decoration/decoration.hpp +265 -0
- data/ext/libieeep1788_copy/p1788/exception/exception.hpp +302 -0
- data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor.hpp +3443 -0
- data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_bool_func_impl.hpp +608 -0
- data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_cancel_func_impl.hpp +229 -0
- data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_class_impl.hpp +526 -0
- data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_elem_func_impl.hpp +4533 -0
- data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_io_impl.hpp +1421 -0
- data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_mul_rev_to_pair_func_impl.hpp +347 -0
- data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_num_func_impl.hpp +655 -0
- data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_rec_bool_func_impl.hpp +146 -0
- data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_rec_overlap_impl.hpp +188 -0
- data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_rev_func_impl.hpp +1674 -0
- data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_set_op_impl.hpp +216 -0
- data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_setup_func_impl.hpp +68 -0
- data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_util_func_impl.hpp +135 -0
- data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_validation_func_impl.hpp +93 -0
- data/ext/libieeep1788_copy/p1788/infsup/base_interval.hpp +1529 -0
- data/ext/libieeep1788_copy/p1788/infsup/base_interval_bool_func_impl.hpp +481 -0
- data/ext/libieeep1788_copy/p1788/infsup/base_interval_cancel_func_impl.hpp +126 -0
- data/ext/libieeep1788_copy/p1788/infsup/base_interval_elem_func_impl.hpp +1581 -0
- data/ext/libieeep1788_copy/p1788/infsup/base_interval_io_impl.hpp +59 -0
- data/ext/libieeep1788_copy/p1788/infsup/base_interval_mul_rev_to_pair_func_impl.hpp +88 -0
- data/ext/libieeep1788_copy/p1788/infsup/base_interval_num_func_impl.hpp +345 -0
- data/ext/libieeep1788_copy/p1788/infsup/base_interval_rec_bool_func_impl.hpp +92 -0
- data/ext/libieeep1788_copy/p1788/infsup/base_interval_rec_overlap_impl.hpp +72 -0
- data/ext/libieeep1788_copy/p1788/infsup/base_interval_rev_func_impl.hpp +656 -0
- data/ext/libieeep1788_copy/p1788/infsup/base_interval_set_op_impl.hpp +126 -0
- data/ext/libieeep1788_copy/p1788/infsup/decorated_interval.hpp +464 -0
- data/ext/libieeep1788_copy/p1788/infsup/forward_declaration.hpp +66 -0
- data/ext/libieeep1788_copy/p1788/infsup/interval.hpp +275 -0
- data/ext/libieeep1788_copy/p1788/io/io_manip.hpp +531 -0
- data/ext/libieeep1788_copy/p1788/overlapping/overlapping.hpp +241 -0
- data/ext/libieeep1788_copy/p1788/p1788.hpp +45 -0
- data/ext/libieeep1788_copy/p1788/reduction/reduction.hpp +341 -0
- data/ext/libieeep1788_copy/p1788/util/io.hpp +63 -0
- data/ext/libieeep1788_copy/p1788/util/mixed_type_traits.hpp +140 -0
- data/ext/libieeep1788_copy/p1788/util/mpfr_util.hpp +77 -0
- data/ext/libieeep1788_copy/p1788/util/mpfr_var.hpp +119 -0
- data/ext/libieeep1788_copy/p1788/util/mpfr_var_impl.hpp +382 -0
- data/ext/libieeep1788_copy/p1788/version.hpp +34 -0
- data/ext/p1788/extconf.rb +49 -0
- data/ext/p1788/p1788.cc +3764 -0
- data/lib/p1788/version.rb +4 -0
- data/lib/p1788.rb +25 -0
- data/p1788.gemspec +72 -0
- metadata +99 -0
@@ -0,0 +1,241 @@
|
|
1
|
+
//
|
2
|
+
// libieeep1788
|
3
|
+
//
|
4
|
+
// An implementation of the preliminary IEEE P1788 standard for
|
5
|
+
// interval arithmetic
|
6
|
+
//
|
7
|
+
//
|
8
|
+
// Copyright 2013 - 2015
|
9
|
+
//
|
10
|
+
// Marco Nehmeier (nehmeier@informatik.uni-wuerzburg.de)
|
11
|
+
// Department of Computer Science,
|
12
|
+
// University of Wuerzburg, Germany
|
13
|
+
//
|
14
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
15
|
+
// you may not use this file except in compliance with the License.
|
16
|
+
// You may obtain a copy of the License at
|
17
|
+
//
|
18
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
19
|
+
//
|
20
|
+
// Unless required by applicable law or agreed to in writing, software
|
21
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
22
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
23
|
+
// See the License for the specific language governing permissions and
|
24
|
+
// limitations under the License.
|
25
|
+
|
26
|
+
|
27
|
+
#ifndef LIBIEEEP1788_P1788_OVERLAPPING_OVERLAPPING_HPP
|
28
|
+
#define LIBIEEEP1788_P1788_OVERLAPPING_OVERLAPPING_HPP
|
29
|
+
|
30
|
+
#include <iostream>
|
31
|
+
#include "p1788/io/io_manip.hpp"
|
32
|
+
|
33
|
+
#include <cstdint>
|
34
|
+
|
35
|
+
namespace p1788
|
36
|
+
{
|
37
|
+
|
38
|
+
namespace overlapping
|
39
|
+
{
|
40
|
+
|
41
|
+
|
42
|
+
// \brief Enum describing the 16 states of the interval overlapping
|
43
|
+
// see P1788/D7.0 Sect. 9.7.2 Table 6
|
44
|
+
//
|
45
|
+
enum class overlapping_state : uint32_t
|
46
|
+
{
|
47
|
+
undefined = 0,
|
48
|
+
both_empty = 1 << 0,
|
49
|
+
first_empty = 1 << 1,
|
50
|
+
second_empty = 1 << 2,
|
51
|
+
before = 1 << 3,
|
52
|
+
meets = 1 << 4,
|
53
|
+
overlaps = 1 << 5,
|
54
|
+
starts = 1 << 6,
|
55
|
+
contained_by = 1 << 7,
|
56
|
+
finishes = 1 << 8,
|
57
|
+
equal = 1 << 9,
|
58
|
+
finished_by = 1 << 10,
|
59
|
+
contains = 1 << 11,
|
60
|
+
started_by = 1 << 12,
|
61
|
+
overlapped_by = 1 << 13,
|
62
|
+
met_by = 1 << 14,
|
63
|
+
after = 1 << 15
|
64
|
+
};
|
65
|
+
|
66
|
+
|
67
|
+
/// \brief Operator for writing an overlapping state onto an output stream.
|
68
|
+
///
|
69
|
+
/// \param os Output stream
|
70
|
+
/// \param o Overlapping state to write onto the output stream \p os
|
71
|
+
/// \return Output stream \p os to support operator chaining
|
72
|
+
///
|
73
|
+
/// \note The function pays attention to the output manipulators
|
74
|
+
/// \link p1788::io::overlapping_alpha(std::basic_ostream<CharT, Traits>& os) overlapping_alpha \endlink ,
|
75
|
+
/// and \link p1788::io::overlapping_numeric(std::basic_ostream<CharT, Traits>& os) overlapping_numeric \endlink
|
76
|
+
/// as well as to
|
77
|
+
/// \link p1788::io::lower_case(std::basic_ostream<CharT, Traits>& os) lower_case \endlink
|
78
|
+
/// and \link p1788::io::upper_case(std::basic_ostream<CharT, Traits>& os) upper_case \endlink .
|
79
|
+
template<typename CharT, typename Traits>
|
80
|
+
std::basic_ostream<CharT, Traits>& operator<<(
|
81
|
+
std::basic_ostream<CharT, Traits>& os, overlapping_state o)
|
82
|
+
{
|
83
|
+
// numeric
|
84
|
+
if (os.iword(p1788::io::overlapping_manip_id) == p1788::io::overlapping_numeric_representation)
|
85
|
+
{
|
86
|
+
return os << static_cast<unsigned int>(o);
|
87
|
+
}
|
88
|
+
|
89
|
+
// alphabetic
|
90
|
+
switch (o)
|
91
|
+
{
|
92
|
+
case overlapping_state::both_empty:
|
93
|
+
switch (os.iword(p1788::io::text_representation_manip_id))
|
94
|
+
{
|
95
|
+
case p1788::io::upper_case_text_representation:
|
96
|
+
return os << "BOTH_EMPTY";
|
97
|
+
default:
|
98
|
+
return os << "both_empty";
|
99
|
+
}
|
100
|
+
case overlapping_state::first_empty:
|
101
|
+
switch (os.iword(p1788::io::text_representation_manip_id))
|
102
|
+
{
|
103
|
+
case p1788::io::upper_case_text_representation:
|
104
|
+
return os << "FIRST_EMPTY";
|
105
|
+
default:
|
106
|
+
return os << "first_empty";
|
107
|
+
}
|
108
|
+
case overlapping_state::second_empty:
|
109
|
+
switch (os.iword(p1788::io::text_representation_manip_id))
|
110
|
+
{
|
111
|
+
case p1788::io::upper_case_text_representation:
|
112
|
+
return os << "SECOND_EMPTY";
|
113
|
+
default:
|
114
|
+
return os << "second_empty";
|
115
|
+
}
|
116
|
+
case overlapping_state::before:
|
117
|
+
switch (os.iword(p1788::io::text_representation_manip_id))
|
118
|
+
{
|
119
|
+
case p1788::io::upper_case_text_representation:
|
120
|
+
return os << "BEFORE";
|
121
|
+
default:
|
122
|
+
return os << "before";
|
123
|
+
}
|
124
|
+
case overlapping_state::meets:
|
125
|
+
switch (os.iword(p1788::io::text_representation_manip_id))
|
126
|
+
{
|
127
|
+
case p1788::io::upper_case_text_representation:
|
128
|
+
return os << "MEETS";
|
129
|
+
default:
|
130
|
+
return os << "meets";
|
131
|
+
}
|
132
|
+
case overlapping_state::overlaps:
|
133
|
+
switch (os.iword(p1788::io::text_representation_manip_id))
|
134
|
+
{
|
135
|
+
case p1788::io::upper_case_text_representation:
|
136
|
+
return os << "OVERLAPS";
|
137
|
+
default:
|
138
|
+
return os << "overlaps";
|
139
|
+
}
|
140
|
+
case overlapping_state::starts:
|
141
|
+
switch (os.iword(p1788::io::text_representation_manip_id))
|
142
|
+
{
|
143
|
+
case p1788::io::upper_case_text_representation:
|
144
|
+
return os << "STARTS";
|
145
|
+
default:
|
146
|
+
return os << "starts";
|
147
|
+
}
|
148
|
+
case overlapping_state::contained_by:
|
149
|
+
switch (os.iword(p1788::io::text_representation_manip_id))
|
150
|
+
{
|
151
|
+
case p1788::io::upper_case_text_representation:
|
152
|
+
return os << "CONTAINED_BY";
|
153
|
+
default:
|
154
|
+
return os << "contained_by";
|
155
|
+
}
|
156
|
+
case overlapping_state::finishes:
|
157
|
+
switch (os.iword(p1788::io::text_representation_manip_id))
|
158
|
+
{
|
159
|
+
case p1788::io::upper_case_text_representation:
|
160
|
+
return os << "FINISHES";
|
161
|
+
default:
|
162
|
+
return os << "finishes";
|
163
|
+
}
|
164
|
+
case overlapping_state::equal:
|
165
|
+
switch (os.iword(p1788::io::text_representation_manip_id))
|
166
|
+
{
|
167
|
+
case p1788::io::upper_case_text_representation:
|
168
|
+
return os << "EQUAL";
|
169
|
+
default:
|
170
|
+
return os << "equal";
|
171
|
+
}
|
172
|
+
case overlapping_state::finished_by:
|
173
|
+
switch (os.iword(p1788::io::text_representation_manip_id))
|
174
|
+
{
|
175
|
+
case p1788::io::upper_case_text_representation:
|
176
|
+
return os << "FINISHED_BY";
|
177
|
+
default:
|
178
|
+
return os << "finished_by";
|
179
|
+
}
|
180
|
+
case overlapping_state::contains:
|
181
|
+
switch (os.iword(p1788::io::text_representation_manip_id))
|
182
|
+
{
|
183
|
+
case p1788::io::upper_case_text_representation:
|
184
|
+
return os << "CONTAINS";
|
185
|
+
default:
|
186
|
+
return os << "contains";
|
187
|
+
}
|
188
|
+
case overlapping_state::started_by:
|
189
|
+
switch (os.iword(p1788::io::text_representation_manip_id))
|
190
|
+
{
|
191
|
+
case p1788::io::upper_case_text_representation:
|
192
|
+
return os << "STARTED_BY";
|
193
|
+
default:
|
194
|
+
return os << "started_by";
|
195
|
+
}
|
196
|
+
case overlapping_state::overlapped_by:
|
197
|
+
switch (os.iword(p1788::io::text_representation_manip_id))
|
198
|
+
{
|
199
|
+
case p1788::io::upper_case_text_representation:
|
200
|
+
return os << "OVERLAPPED_BY";
|
201
|
+
default:
|
202
|
+
return os << "overlapped_by";
|
203
|
+
}
|
204
|
+
case overlapping_state::met_by:
|
205
|
+
switch (os.iword(p1788::io::text_representation_manip_id))
|
206
|
+
{
|
207
|
+
case p1788::io::upper_case_text_representation:
|
208
|
+
return os << "MET_BY";
|
209
|
+
default:
|
210
|
+
return os << "met_by";
|
211
|
+
}
|
212
|
+
case overlapping_state::after:
|
213
|
+
switch (os.iword(p1788::io::text_representation_manip_id))
|
214
|
+
{
|
215
|
+
case p1788::io::upper_case_text_representation:
|
216
|
+
return os << "AFTER";
|
217
|
+
default:
|
218
|
+
return os << "after";
|
219
|
+
}
|
220
|
+
default: // undefined
|
221
|
+
switch (os.iword(p1788::io::text_representation_manip_id))
|
222
|
+
{
|
223
|
+
case p1788::io::upper_case_text_representation:
|
224
|
+
return os << "UNDEFINED";
|
225
|
+
default:
|
226
|
+
return os << "undefined";
|
227
|
+
}
|
228
|
+
}
|
229
|
+
|
230
|
+
// Something went wrong ;-)
|
231
|
+
return os;
|
232
|
+
}
|
233
|
+
|
234
|
+
|
235
|
+
} // namespace overlapping
|
236
|
+
|
237
|
+
} // namespace p1788
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
#endif // LIBIEEEP1788_P1788_OVERLAPPING_OVERLAPPING_HPP
|
@@ -0,0 +1,45 @@
|
|
1
|
+
//
|
2
|
+
// libieeep1788
|
3
|
+
//
|
4
|
+
// An implementation of the preliminary IEEE P1788 standard for
|
5
|
+
// interval arithmetic
|
6
|
+
//
|
7
|
+
//
|
8
|
+
// Copyright 2013 - 2015
|
9
|
+
//
|
10
|
+
// Marco Nehmeier (nehmeier@informatik.uni-wuerzburg.de)
|
11
|
+
// Department of Computer Science,
|
12
|
+
// University of Wuerzburg, Germany
|
13
|
+
//
|
14
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
15
|
+
// you may not use this file except in compliance with the License.
|
16
|
+
// You may obtain a copy of the License at
|
17
|
+
//
|
18
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
19
|
+
//
|
20
|
+
// Unless required by applicable law or agreed to in writing, software
|
21
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
22
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
23
|
+
// See the License for the specific language governing permissions and
|
24
|
+
// limitations under the License.
|
25
|
+
|
26
|
+
#ifndef LIBIEEEP1788_P1788_P1788_HPP
|
27
|
+
#define LIBIEEEP1788_P1788_P1788_HPP
|
28
|
+
|
29
|
+
|
30
|
+
#include "p1788/version.hpp"
|
31
|
+
|
32
|
+
#include "p1788/decoration/decoration.hpp"
|
33
|
+
#include "p1788/exception/exception.hpp"
|
34
|
+
#include "p1788/io/io_manip.hpp"
|
35
|
+
#include "p1788/overlapping/overlapping.hpp"
|
36
|
+
|
37
|
+
#include "p1788/infsup/interval.hpp"
|
38
|
+
#include "p1788/infsup/decorated_interval.hpp"
|
39
|
+
|
40
|
+
#include "p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor.hpp"
|
41
|
+
|
42
|
+
#include "p1788/reduction/reduction.hpp"
|
43
|
+
|
44
|
+
|
45
|
+
#endif // LIBIEEEP1788_P1788_P1788_HPP
|
@@ -0,0 +1,341 @@
|
|
1
|
+
//
|
2
|
+
// libieeep1788
|
3
|
+
//
|
4
|
+
// An implementation of the preliminary IEEE P1788 standard for
|
5
|
+
// interval arithmetic
|
6
|
+
//
|
7
|
+
//
|
8
|
+
// Copyright 2013 - 2015
|
9
|
+
//
|
10
|
+
// Marco Nehmeier (nehmeier@informatik.uni-wuerzburg.de)
|
11
|
+
// Department of Computer Science,
|
12
|
+
// University of Wuerzburg, Germany
|
13
|
+
//
|
14
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
15
|
+
// you may not use this file except in compliance with the License.
|
16
|
+
// You may obtain a copy of the License at
|
17
|
+
//
|
18
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
19
|
+
//
|
20
|
+
// Unless required by applicable law or agreed to in writing, software
|
21
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
22
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
23
|
+
// See the License for the specific language governing permissions and
|
24
|
+
// limitations under the License.
|
25
|
+
|
26
|
+
|
27
|
+
#ifndef LIBIEEEP1788_P1788_REDUCTION_REDUCTION_HPP
|
28
|
+
#define LIBIEEEP1788_P1788_REDUCTION_REDUCTION_HPP
|
29
|
+
|
30
|
+
#include <iterator>
|
31
|
+
#include <initializer_list>
|
32
|
+
|
33
|
+
#include "p1788/util/mpfr_var.hpp"
|
34
|
+
|
35
|
+
namespace p1788
|
36
|
+
{
|
37
|
+
|
38
|
+
namespace reduction
|
39
|
+
{
|
40
|
+
|
41
|
+
|
42
|
+
// enum for rounding modes
|
43
|
+
enum class rnd_mode
|
44
|
+
{
|
45
|
+
downward = MPFR_RNDD,
|
46
|
+
upward = MPFR_RNDU,
|
47
|
+
to_nearest = MPFR_RNDN,
|
48
|
+
to_zero = MPFR_RNDZ
|
49
|
+
};
|
50
|
+
|
51
|
+
// convert rnd_mode to mpfr rndmode
|
52
|
+
inline mpfr_rnd_t get_mpfr_rnd_mode(rnd_mode rnd)
|
53
|
+
{
|
54
|
+
switch (rnd)
|
55
|
+
{
|
56
|
+
case rnd_mode::downward:
|
57
|
+
return MPFR_RNDD;
|
58
|
+
case rnd_mode::upward:
|
59
|
+
return MPFR_RNDU;
|
60
|
+
case rnd_mode::to_nearest:
|
61
|
+
return MPFR_RNDN;
|
62
|
+
case rnd_mode::to_zero:
|
63
|
+
return MPFR_RNDZ;
|
64
|
+
}
|
65
|
+
|
66
|
+
// Something went wrong
|
67
|
+
return MPFR_RNDN;
|
68
|
+
}
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
// class to perform the accumulation with a combined memory handling (RAII)
|
73
|
+
template<class Iter>
|
74
|
+
class reduction_sum_op
|
75
|
+
{
|
76
|
+
static_assert(std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::is_iec559,
|
77
|
+
"Only IEEE 754 binary compliant types are supported!");
|
78
|
+
|
79
|
+
// Typedef for the corresponding mpfr wrapper class representing the IEEE 754 binary floating point format of the iterator value type
|
80
|
+
typedef p1788::util::mpfr_var<
|
81
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::digits,
|
82
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::has_denorm != std::denorm_present
|
83
|
+
? std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::min_exponent
|
84
|
+
: std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::min_exponent - std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::digits + 1,
|
85
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::max_exponent,
|
86
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::has_denorm == std::denorm_present
|
87
|
+
> mpfr_var;
|
88
|
+
|
89
|
+
public:
|
90
|
+
|
91
|
+
// perform op on one iterator
|
92
|
+
reduction_sum_op(void (*op) (Iter, mpfr_ptr*), Iter begin, Iter end, rnd_mode rnd) : n_(end - begin)
|
93
|
+
{
|
94
|
+
mpfr_var::setup();
|
95
|
+
tab_ = new mpfr_ptr[n_]; // array of elemets
|
96
|
+
|
97
|
+
mpfr_ptr* p = tab_;
|
98
|
+
|
99
|
+
// perform op on iterator
|
100
|
+
while (begin != end)
|
101
|
+
op(begin++, p++);
|
102
|
+
|
103
|
+
mpfr_var res;
|
104
|
+
|
105
|
+
// accumulate
|
106
|
+
res.subnormalize(mpfr_sum(res(), tab_, n_, get_mpfr_rnd_mode(rnd)), get_mpfr_rnd_mode(rnd));
|
107
|
+
|
108
|
+
// get result
|
109
|
+
result_ = res.template get<typename std::iterator_traits<Iter>::value_type>(get_mpfr_rnd_mode(rnd));
|
110
|
+
|
111
|
+
if (result_ == 0.0)
|
112
|
+
result_ = rnd == rnd_mode::downward ? -0.0 : 0.0;
|
113
|
+
}
|
114
|
+
|
115
|
+
// perform op on two interators
|
116
|
+
reduction_sum_op(void (*op) (Iter, Iter, mpfr_ptr*), Iter begin_a, Iter end_a, Iter begin_b, rnd_mode rnd) : n_(end_a - begin_a)
|
117
|
+
{
|
118
|
+
mpfr_var::setup();
|
119
|
+
tab_ = new mpfr_ptr[n_]; // array of elemets
|
120
|
+
|
121
|
+
mpfr_ptr* p = tab_;
|
122
|
+
|
123
|
+
// perform op on iterator
|
124
|
+
while (begin_a != end_a)
|
125
|
+
op(begin_a++, begin_b++, p++);
|
126
|
+
|
127
|
+
mpfr_var res;
|
128
|
+
|
129
|
+
// accumulate
|
130
|
+
res.subnormalize(mpfr_sum(res(), tab_, n_, get_mpfr_rnd_mode(rnd)), get_mpfr_rnd_mode(rnd));
|
131
|
+
|
132
|
+
// get result
|
133
|
+
result_ = res.template get<typename std::iterator_traits<Iter>::value_type>(get_mpfr_rnd_mode(rnd));
|
134
|
+
|
135
|
+
if (result_ == 0.0)
|
136
|
+
result_ = rnd == rnd_mode::downward ? -0.0 : 0.0;
|
137
|
+
}
|
138
|
+
|
139
|
+
// cleanup
|
140
|
+
~reduction_sum_op()
|
141
|
+
{
|
142
|
+
for(mpfr_ptr* b = tab_; b != tab_ + n_; ++b)
|
143
|
+
mpfr_clear(*b);
|
144
|
+
|
145
|
+
delete[] tab_;
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
// get result
|
150
|
+
typename std::iterator_traits<Iter>::value_type
|
151
|
+
result()
|
152
|
+
{
|
153
|
+
return result_;
|
154
|
+
}
|
155
|
+
|
156
|
+
private:
|
157
|
+
size_t const n_;
|
158
|
+
typename std::iterator_traits<Iter>::value_type result_;
|
159
|
+
mpfr_ptr* tab_;
|
160
|
+
};
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
// sum
|
166
|
+
template<class Iter>
|
167
|
+
typename std::iterator_traits<Iter>::value_type
|
168
|
+
inline sum(Iter begin, Iter end, rnd_mode rnd)
|
169
|
+
{
|
170
|
+
// Typedef for the corresponding mpfr wrapper class representing the IEEE 754 binary floating point format of the iterator value type
|
171
|
+
typedef p1788::util::mpfr_var<
|
172
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::digits,
|
173
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::has_denorm != std::denorm_present
|
174
|
+
? std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::min_exponent
|
175
|
+
: std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::min_exponent - std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::digits + 1,
|
176
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::max_exponent,
|
177
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::has_denorm == std::denorm_present
|
178
|
+
> mpfr_var;
|
179
|
+
|
180
|
+
reduction_sum_op<Iter> op(
|
181
|
+
[] (Iter i, mpfr_ptr* p)
|
182
|
+
{
|
183
|
+
*p = new mpfr_t;
|
184
|
+
|
185
|
+
mpfr_init2(*p, std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::digits);
|
186
|
+
|
187
|
+
mpfr_var tmp(*i, MPFR_RNDN);
|
188
|
+
|
189
|
+
mpfr_set(*p, tmp(), MPFR_RNDN);
|
190
|
+
},
|
191
|
+
begin, end, rnd
|
192
|
+
);
|
193
|
+
|
194
|
+
return op.result();
|
195
|
+
}
|
196
|
+
|
197
|
+
// sum
|
198
|
+
template<typename T>
|
199
|
+
T
|
200
|
+
inline sum(std::initializer_list<T> l, rnd_mode rnd)
|
201
|
+
{
|
202
|
+
return sum(std::begin(l), std::end(l), rnd);
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
// sum_abs
|
207
|
+
template<class Iter>
|
208
|
+
typename std::iterator_traits<Iter>::value_type
|
209
|
+
inline sum_abs(Iter begin, Iter end, rnd_mode rnd)
|
210
|
+
{
|
211
|
+
// Typedef for the corresponding mpfr wrapper class representing the IEEE 754 binary floating point format of the iterator value type
|
212
|
+
typedef p1788::util::mpfr_var<
|
213
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::digits,
|
214
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::has_denorm != std::denorm_present
|
215
|
+
? std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::min_exponent
|
216
|
+
: std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::min_exponent - std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::digits + 1,
|
217
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::max_exponent,
|
218
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::has_denorm == std::denorm_present
|
219
|
+
> mpfr_var;
|
220
|
+
|
221
|
+
reduction_sum_op<Iter> op(
|
222
|
+
[] (Iter i, mpfr_ptr* p)
|
223
|
+
{
|
224
|
+
*p = new mpfr_t;
|
225
|
+
|
226
|
+
mpfr_init2(*p, std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::digits);
|
227
|
+
|
228
|
+
mpfr_var tmp(*i, MPFR_RNDN);
|
229
|
+
mpfr_abs(tmp(), tmp(), MPFR_RNDN);
|
230
|
+
|
231
|
+
mpfr_set(*p, tmp(), MPFR_RNDN);
|
232
|
+
},
|
233
|
+
begin, end, rnd
|
234
|
+
);
|
235
|
+
|
236
|
+
return op.result();
|
237
|
+
}
|
238
|
+
|
239
|
+
// sum_abs
|
240
|
+
template<typename T>
|
241
|
+
T
|
242
|
+
inline sum_abs(std::initializer_list<T> l, rnd_mode rnd)
|
243
|
+
{
|
244
|
+
return sum_abs(std::begin(l), std::end(l), rnd);
|
245
|
+
}
|
246
|
+
|
247
|
+
|
248
|
+
// sum_sqr
|
249
|
+
template<class Iter>
|
250
|
+
typename std::iterator_traits<Iter>::value_type
|
251
|
+
inline sum_sqr(Iter begin, Iter end, rnd_mode rnd)
|
252
|
+
{
|
253
|
+
// Typedef for the corresponding mpfr wrapper class representing the IEEE 754 binary floating point format of the iterator value type with twice the mantissa size
|
254
|
+
typedef p1788::util::mpfr_var<
|
255
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::digits * 2,
|
256
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::has_denorm != std::denorm_present
|
257
|
+
? std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::min_exponent
|
258
|
+
: std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::min_exponent - std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::digits * 2 + 1,
|
259
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::max_exponent,
|
260
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::has_denorm == std::denorm_present
|
261
|
+
> mpfr_var;
|
262
|
+
|
263
|
+
reduction_sum_op<Iter> op(
|
264
|
+
[] (Iter i, mpfr_ptr* p)
|
265
|
+
{
|
266
|
+
*p = new mpfr_t;
|
267
|
+
|
268
|
+
mpfr_init2(*p, std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::digits * 2);
|
269
|
+
|
270
|
+
mpfr_var tmp(*i, MPFR_RNDN);
|
271
|
+
mpfr_sqr(tmp(), tmp(), MPFR_RNDN);
|
272
|
+
|
273
|
+
mpfr_set(*p, tmp(), MPFR_RNDN);
|
274
|
+
},
|
275
|
+
begin, end, rnd
|
276
|
+
);
|
277
|
+
|
278
|
+
return op.result();
|
279
|
+
}
|
280
|
+
|
281
|
+
// sum_sqr
|
282
|
+
template<typename T>
|
283
|
+
T
|
284
|
+
inline sum_sqr(std::initializer_list<T> l, rnd_mode rnd)
|
285
|
+
{
|
286
|
+
return sum_sqr(std::begin(l), std::end(l), rnd);
|
287
|
+
}
|
288
|
+
|
289
|
+
|
290
|
+
// dot
|
291
|
+
template<class Iter>
|
292
|
+
typename std::iterator_traits<Iter>::value_type
|
293
|
+
inline dot(Iter begin_a, Iter end_a, Iter begin_b, rnd_mode rnd)
|
294
|
+
{
|
295
|
+
// Typedef for the corresponding mpfr wrapper class representing the IEEE 754 binary floating point format of the iterator value type with twice the mantissa size
|
296
|
+
typedef p1788::util::mpfr_var<
|
297
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::digits * 2,
|
298
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::has_denorm != std::denorm_present
|
299
|
+
? std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::min_exponent
|
300
|
+
: std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::min_exponent - std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::digits * 2 + 1,
|
301
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::max_exponent,
|
302
|
+
std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::has_denorm == std::denorm_present
|
303
|
+
> mpfr_var;
|
304
|
+
|
305
|
+
reduction_sum_op<Iter> op(
|
306
|
+
[] (Iter a, Iter b, mpfr_ptr* p)
|
307
|
+
{
|
308
|
+
*p = new mpfr_t;
|
309
|
+
|
310
|
+
mpfr_init2(*p, std::numeric_limits<typename std::iterator_traits<Iter>::value_type>::digits * 2);
|
311
|
+
|
312
|
+
mpfr_var tmp_a(*a, MPFR_RNDN);
|
313
|
+
mpfr_var tmp_b(*b, MPFR_RNDN);
|
314
|
+
|
315
|
+
mpfr_mul(tmp_a(), tmp_a(), tmp_b(), MPFR_RNDN);
|
316
|
+
|
317
|
+
mpfr_set(*p, tmp_a(), MPFR_RNDN);
|
318
|
+
},
|
319
|
+
begin_a, end_a, begin_b, rnd
|
320
|
+
);
|
321
|
+
|
322
|
+
return op.result();
|
323
|
+
}
|
324
|
+
|
325
|
+
// dot
|
326
|
+
template<typename T>
|
327
|
+
T
|
328
|
+
inline dot(std::initializer_list<T> a, std::initializer_list<T> b, rnd_mode rnd)
|
329
|
+
{
|
330
|
+
return dot(std::begin(a), std::end(a), std::begin(b), rnd);
|
331
|
+
}
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
} // namespace reduction
|
336
|
+
|
337
|
+
} // namespace p1788
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
#endif // LIBIEEEP1788_P1788_REDUCTION_REDUCTION_HPP
|
@@ -0,0 +1,63 @@
|
|
1
|
+
// An implementation of the preliminary IEEE P1788 standard for
|
2
|
+
// interval arithmetic
|
3
|
+
//
|
4
|
+
//
|
5
|
+
// Copyright 2013 - 2015
|
6
|
+
//
|
7
|
+
// Marco Nehmeier (nehmeier@informatik.uni-wuerzburg.de)
|
8
|
+
// Department of Computer Science,
|
9
|
+
// University of Wuerzburg, Germany
|
10
|
+
//
|
11
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
12
|
+
// you may not use this file except in compliance with the License.
|
13
|
+
// You may obtain a copy of the License at
|
14
|
+
//
|
15
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
16
|
+
//
|
17
|
+
// Unless required by applicable law or agreed to in writing, software
|
18
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
19
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
20
|
+
// See the License for the specific language governing permissions and
|
21
|
+
// limitations under the License.
|
22
|
+
|
23
|
+
#ifndef LIBIEEEP1788_P1788_UTIL_IO_HPP
|
24
|
+
#define LIBIEEEP1788_P1788_UTIL_IO_HPP
|
25
|
+
|
26
|
+
#include <iostream>
|
27
|
+
#include <cctype>
|
28
|
+
#include <ctype.h>
|
29
|
+
#include <string>
|
30
|
+
#include <algorithm>
|
31
|
+
|
32
|
+
namespace p1788
|
33
|
+
{
|
34
|
+
|
35
|
+
namespace util
|
36
|
+
{
|
37
|
+
|
38
|
+
// Remove whitespace character from input stream
|
39
|
+
template<typename CharT, typename Traits>
|
40
|
+
inline void remove_ws(std::basic_istream<CharT, Traits>& is)
|
41
|
+
{
|
42
|
+
while (is && std::isspace(is.peek()))
|
43
|
+
is.get();
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
// transform all ASCII characters to lowercase
|
49
|
+
inline void ascii_to_lower(std::string& s)
|
50
|
+
{
|
51
|
+
std::transform(s.begin(), s.end(), s.begin(),
|
52
|
+
[](int const c)
|
53
|
+
{
|
54
|
+
return (c >= 0 && c < 128 ) ? std::tolower(c) : c;
|
55
|
+
}
|
56
|
+
);
|
57
|
+
}
|
58
|
+
|
59
|
+
} // namespace util
|
60
|
+
|
61
|
+
} // namespace p1788
|
62
|
+
|
63
|
+
#endif // LIBIEEEP1788_P1788_UTIL_IO_HPP
|