p1788 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_cancel_func_impl.hpp
ADDED
@@ -0,0 +1,229 @@
|
|
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_FLAVOR_INFSUP_SETBASED_MPFR_BIN_IEEE754_FLAVOR_CANCEL_FUNC_IMPL_HPP
|
27
|
+
#define LIBIEEEP1788_P1788_FLAVOR_INFSUP_SETBASED_MPFR_BIN_IEEE754_FLAVOR_CANCEL_FUNC_IMPL_HPP
|
28
|
+
|
29
|
+
|
30
|
+
namespace p1788
|
31
|
+
{
|
32
|
+
|
33
|
+
namespace flavor
|
34
|
+
{
|
35
|
+
|
36
|
+
namespace infsup
|
37
|
+
{
|
38
|
+
|
39
|
+
namespace setbased
|
40
|
+
{
|
41
|
+
|
42
|
+
template<typename T>
|
43
|
+
typename mpfr_bin_ieee754_flavor<T>::representation
|
44
|
+
mpfr_bin_ieee754_flavor<T>::cancel_plus(mpfr_bin_ieee754_flavor<T>::representation const& x,
|
45
|
+
mpfr_bin_ieee754_flavor<T>::representation const& y)
|
46
|
+
{
|
47
|
+
return cancel_minus(x, neg(y));
|
48
|
+
}
|
49
|
+
|
50
|
+
template<typename T>
|
51
|
+
template<typename T1, typename T2>
|
52
|
+
typename mpfr_bin_ieee754_flavor<T>::representation
|
53
|
+
mpfr_bin_ieee754_flavor<T>::cancel_plus(mpfr_bin_ieee754_flavor<T>::representation_type<T1> const& x,
|
54
|
+
mpfr_bin_ieee754_flavor<T>::representation_type<T2> const& y)
|
55
|
+
{
|
56
|
+
static_assert(std::numeric_limits<T1>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
|
57
|
+
static_assert(std::numeric_limits<T2>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
|
58
|
+
|
59
|
+
return cancel_minus(x, neg(y));
|
60
|
+
}
|
61
|
+
|
62
|
+
template<typename T>
|
63
|
+
typename mpfr_bin_ieee754_flavor<T>::representation_dec
|
64
|
+
mpfr_bin_ieee754_flavor<T>::cancel_plus(mpfr_bin_ieee754_flavor<T>::representation_dec const& x,
|
65
|
+
mpfr_bin_ieee754_flavor<T>::representation_dec const& y)
|
66
|
+
{
|
67
|
+
return cancel_minus(x, neg(y));
|
68
|
+
}
|
69
|
+
|
70
|
+
template<typename T>
|
71
|
+
template<typename T1, typename T2>
|
72
|
+
typename mpfr_bin_ieee754_flavor<T>::representation_dec
|
73
|
+
mpfr_bin_ieee754_flavor<T>::cancel_plus(mpfr_bin_ieee754_flavor<T>::representation_dec_type<T1> const& x,
|
74
|
+
mpfr_bin_ieee754_flavor<T>::representation_dec_type<T2> const& y)
|
75
|
+
{
|
76
|
+
static_assert(std::numeric_limits<T1>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
|
77
|
+
static_assert(std::numeric_limits<T2>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
|
78
|
+
|
79
|
+
return cancel_minus(x, neg(y));
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
template<typename T>
|
85
|
+
typename mpfr_bin_ieee754_flavor<T>::representation
|
86
|
+
mpfr_bin_ieee754_flavor<T>::cancel_minus(mpfr_bin_ieee754_flavor<T>::representation const& x,
|
87
|
+
mpfr_bin_ieee754_flavor<T>::representation const& y)
|
88
|
+
{
|
89
|
+
if (!is_valid(x) || !is_valid(x))
|
90
|
+
return empty();
|
91
|
+
|
92
|
+
if (x.first == -std::numeric_limits<T>::infinity()
|
93
|
+
|| x.second == +std::numeric_limits<T>::infinity()
|
94
|
+
|| y.first == -std::numeric_limits<T>::infinity()
|
95
|
+
|| y.second == +std::numeric_limits<T>::infinity())
|
96
|
+
return entire();
|
97
|
+
|
98
|
+
p1788::overlapping::overlapping_state os = overlap(x, y);
|
99
|
+
|
100
|
+
// if (is_empty(x))
|
101
|
+
if (os == p1788::overlapping::overlapping_state::first_empty
|
102
|
+
|| os == p1788::overlapping::overlapping_state::both_empty)
|
103
|
+
return x;
|
104
|
+
|
105
|
+
// if (is_empty(y))
|
106
|
+
if (os == p1788::overlapping::overlapping_state::second_empty)
|
107
|
+
return entire();
|
108
|
+
|
109
|
+
|
110
|
+
// if (wid(x) < wid(y))
|
111
|
+
if (os == p1788::overlapping::overlapping_state::starts
|
112
|
+
|| os == p1788::overlapping::overlapping_state::contained_by
|
113
|
+
|| os == p1788::overlapping::overlapping_state::finishes)
|
114
|
+
return entire();
|
115
|
+
|
116
|
+
if (os == p1788::overlapping::overlapping_state::before
|
117
|
+
|| os == p1788::overlapping::overlapping_state::meets
|
118
|
+
|| os == p1788::overlapping::overlapping_state::met_by
|
119
|
+
|| os == p1788::overlapping::overlapping_state::after)
|
120
|
+
{
|
121
|
+
auto x_wid = p1788::util::two_sum(x.second, -x.first);
|
122
|
+
auto y_wid = p1788::util::two_sum(y.second, -y.first);
|
123
|
+
if (x_wid.first < y_wid.first || (x_wid.first == y_wid.first && x_wid.second < y_wid.second))
|
124
|
+
return entire();
|
125
|
+
}
|
126
|
+
|
127
|
+
if (os == p1788::overlapping::overlapping_state::overlaps
|
128
|
+
|| os == p1788::overlapping::overlapping_state::overlapped_by)
|
129
|
+
{
|
130
|
+
auto upper_dist = p1788::util::two_sum(y.second, -x.second);
|
131
|
+
auto lower_dist = p1788::util::two_sum(y.first, -x.first);
|
132
|
+
if (lower_dist.first < upper_dist.first || (lower_dist.first == upper_dist.first && lower_dist.second < upper_dist.second))
|
133
|
+
return entire();
|
134
|
+
}
|
135
|
+
|
136
|
+
mpfr_var::setup();
|
137
|
+
|
138
|
+
mpfr_var xl(x.first, MPFR_RNDD);
|
139
|
+
mpfr_var xu(x.second, MPFR_RNDU);
|
140
|
+
|
141
|
+
mpfr_var yl(y.first, MPFR_RNDD);
|
142
|
+
mpfr_var yu(y.second, MPFR_RNDU);
|
143
|
+
|
144
|
+
|
145
|
+
mpfr_sub(xl(), xl(), yl(), MPFR_RNDD);
|
146
|
+
mpfr_sub(xu(), xu(), yu(), MPFR_RNDU);
|
147
|
+
|
148
|
+
return representation(xl.template get<T>(MPFR_RNDD), xu.template get<T>(MPFR_RNDU));
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
template<typename T>
|
153
|
+
template<typename T1, typename T2>
|
154
|
+
typename mpfr_bin_ieee754_flavor<T>::representation
|
155
|
+
mpfr_bin_ieee754_flavor<T>::cancel_minus(mpfr_bin_ieee754_flavor<T>::representation_type<T1> const& x,
|
156
|
+
mpfr_bin_ieee754_flavor<T>::representation_type<T2> const& y)
|
157
|
+
{
|
158
|
+
static_assert(std::numeric_limits<T1>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
|
159
|
+
static_assert(std::numeric_limits<T2>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
|
160
|
+
|
161
|
+
if (!mpfr_bin_ieee754_flavor<T1>::is_valid(x) || !mpfr_bin_ieee754_flavor<T2>::is_valid(y))
|
162
|
+
return empty();
|
163
|
+
|
164
|
+
// determine max. precision
|
165
|
+
typedef typename p1788::util::max_precision_type<T,T1,T2>::type T_MAX;
|
166
|
+
|
167
|
+
// 1.) convert inputs to max precision; 2.) compute result in max precision; 3.) convert result to desired precision
|
168
|
+
// Error free for floating point inf-sup intervals due to outward rounding
|
169
|
+
return convert_hull(
|
170
|
+
mpfr_bin_ieee754_flavor<T_MAX>::cancel_minus(
|
171
|
+
mpfr_bin_ieee754_flavor<T_MAX>::convert_hull(x),
|
172
|
+
mpfr_bin_ieee754_flavor<T_MAX>::convert_hull(y)
|
173
|
+
)
|
174
|
+
);
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
template<typename T>
|
179
|
+
typename mpfr_bin_ieee754_flavor<T>::representation_dec
|
180
|
+
mpfr_bin_ieee754_flavor<T>::cancel_minus(mpfr_bin_ieee754_flavor<T>::representation_dec const& x,
|
181
|
+
mpfr_bin_ieee754_flavor<T>::representation_dec const& y)
|
182
|
+
{
|
183
|
+
if (!is_valid(x) || !is_valid(y) || is_nai(x) || is_nai(y))
|
184
|
+
return nai();
|
185
|
+
|
186
|
+
// compute bare result
|
187
|
+
representation bare = cancel_minus(x.first, y.first);
|
188
|
+
|
189
|
+
return representation_dec(bare, p1788::decoration::decoration::trv);
|
190
|
+
}
|
191
|
+
|
192
|
+
|
193
|
+
template<typename T>
|
194
|
+
template<typename T1, typename T2>
|
195
|
+
typename mpfr_bin_ieee754_flavor<T>::representation_dec
|
196
|
+
mpfr_bin_ieee754_flavor<T>::cancel_minus(mpfr_bin_ieee754_flavor<T>::representation_dec_type<T1> const& x,
|
197
|
+
mpfr_bin_ieee754_flavor<T>::representation_dec_type<T2> const& y)
|
198
|
+
{
|
199
|
+
static_assert(std::numeric_limits<T1>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
|
200
|
+
static_assert(std::numeric_limits<T2>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
|
201
|
+
|
202
|
+
if (!mpfr_bin_ieee754_flavor<T1>::is_valid(x) || !mpfr_bin_ieee754_flavor<T2>::is_valid(y)
|
203
|
+
|| mpfr_bin_ieee754_flavor<T1>::is_nai(x) || mpfr_bin_ieee754_flavor<T2>::is_nai(y))
|
204
|
+
return nai();
|
205
|
+
|
206
|
+
// determine max. precision
|
207
|
+
typedef typename p1788::util::max_precision_type<T,T1,T2>::type T_MAX;
|
208
|
+
|
209
|
+
// 1.) convert inputs to max precision; 2.) compute result in max precision; 3.) convert result to desired precision
|
210
|
+
// Error free for floating point inf-sup intervals due to outward rounding
|
211
|
+
return convert_hull(
|
212
|
+
mpfr_bin_ieee754_flavor<T_MAX>::cancel_minus(
|
213
|
+
mpfr_bin_ieee754_flavor<T_MAX>::convert_hull(x),
|
214
|
+
mpfr_bin_ieee754_flavor<T_MAX>::convert_hull(y)
|
215
|
+
)
|
216
|
+
);
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
} // namespace setbased
|
221
|
+
|
222
|
+
} // namespace infsup
|
223
|
+
|
224
|
+
} // namespace flavor
|
225
|
+
|
226
|
+
} // namespace p1788
|
227
|
+
|
228
|
+
|
229
|
+
#endif // LIBIEEEP1788_P1788_FLAVOR_INFSUP_SETBASED_MPFR_BIN_IEEE754_FLAVOR_CANCEL_FUNC_IMPL_HPP
|