p1788 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +8 -0
  3. data/AUTHORS +6 -0
  4. data/LICENSE +201 -0
  5. data/NOTICE +29 -0
  6. data/README.md +65 -0
  7. data/ext/libieeep1788_copy/README +3 -0
  8. data/ext/libieeep1788_copy/p1788/AUTHORS +16 -0
  9. data/ext/libieeep1788_copy/p1788/LICENSE +202 -0
  10. data/ext/libieeep1788_copy/p1788/NOTICE +14 -0
  11. data/ext/libieeep1788_copy/p1788/decoration/decoration.hpp +265 -0
  12. data/ext/libieeep1788_copy/p1788/exception/exception.hpp +302 -0
  13. data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor.hpp +3443 -0
  14. data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_bool_func_impl.hpp +608 -0
  15. data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_cancel_func_impl.hpp +229 -0
  16. data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_class_impl.hpp +526 -0
  17. data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_elem_func_impl.hpp +4533 -0
  18. data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_io_impl.hpp +1421 -0
  19. data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_mul_rev_to_pair_func_impl.hpp +347 -0
  20. data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_num_func_impl.hpp +655 -0
  21. data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_rec_bool_func_impl.hpp +146 -0
  22. data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_rec_overlap_impl.hpp +188 -0
  23. data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_rev_func_impl.hpp +1674 -0
  24. data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_set_op_impl.hpp +216 -0
  25. data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_setup_func_impl.hpp +68 -0
  26. data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_util_func_impl.hpp +135 -0
  27. data/ext/libieeep1788_copy/p1788/flavor/infsup/setbased/mpfr_bin_ieee754_flavor_validation_func_impl.hpp +93 -0
  28. data/ext/libieeep1788_copy/p1788/infsup/base_interval.hpp +1529 -0
  29. data/ext/libieeep1788_copy/p1788/infsup/base_interval_bool_func_impl.hpp +481 -0
  30. data/ext/libieeep1788_copy/p1788/infsup/base_interval_cancel_func_impl.hpp +126 -0
  31. data/ext/libieeep1788_copy/p1788/infsup/base_interval_elem_func_impl.hpp +1581 -0
  32. data/ext/libieeep1788_copy/p1788/infsup/base_interval_io_impl.hpp +59 -0
  33. data/ext/libieeep1788_copy/p1788/infsup/base_interval_mul_rev_to_pair_func_impl.hpp +88 -0
  34. data/ext/libieeep1788_copy/p1788/infsup/base_interval_num_func_impl.hpp +345 -0
  35. data/ext/libieeep1788_copy/p1788/infsup/base_interval_rec_bool_func_impl.hpp +92 -0
  36. data/ext/libieeep1788_copy/p1788/infsup/base_interval_rec_overlap_impl.hpp +72 -0
  37. data/ext/libieeep1788_copy/p1788/infsup/base_interval_rev_func_impl.hpp +656 -0
  38. data/ext/libieeep1788_copy/p1788/infsup/base_interval_set_op_impl.hpp +126 -0
  39. data/ext/libieeep1788_copy/p1788/infsup/decorated_interval.hpp +464 -0
  40. data/ext/libieeep1788_copy/p1788/infsup/forward_declaration.hpp +66 -0
  41. data/ext/libieeep1788_copy/p1788/infsup/interval.hpp +275 -0
  42. data/ext/libieeep1788_copy/p1788/io/io_manip.hpp +531 -0
  43. data/ext/libieeep1788_copy/p1788/overlapping/overlapping.hpp +241 -0
  44. data/ext/libieeep1788_copy/p1788/p1788.hpp +45 -0
  45. data/ext/libieeep1788_copy/p1788/reduction/reduction.hpp +341 -0
  46. data/ext/libieeep1788_copy/p1788/util/io.hpp +63 -0
  47. data/ext/libieeep1788_copy/p1788/util/mixed_type_traits.hpp +140 -0
  48. data/ext/libieeep1788_copy/p1788/util/mpfr_util.hpp +77 -0
  49. data/ext/libieeep1788_copy/p1788/util/mpfr_var.hpp +119 -0
  50. data/ext/libieeep1788_copy/p1788/util/mpfr_var_impl.hpp +382 -0
  51. data/ext/libieeep1788_copy/p1788/version.hpp +34 -0
  52. data/ext/p1788/extconf.rb +49 -0
  53. data/ext/p1788/p1788.cc +3764 -0
  54. data/lib/p1788/version.rb +4 -0
  55. data/lib/p1788.rb +25 -0
  56. data/p1788.gemspec +72 -0
  57. metadata +99 -0
@@ -0,0 +1,655 @@
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_NUM_FUNC_IMPL_HPP
27
+ #define LIBIEEEP1788_P1788_FLAVOR_INFSUP_SETBASED_MPFR_BIN_IEEE754_FLAVOR_NUM_FUNC_IMPL_HPP
28
+
29
+ namespace p1788
30
+ {
31
+
32
+ namespace flavor
33
+ {
34
+
35
+ namespace infsup
36
+ {
37
+
38
+ namespace setbased
39
+ {
40
+
41
+ // inf ( bare interval )
42
+ template<typename T>
43
+ T
44
+ mpfr_bin_ieee754_flavor<T>::inf(mpfr_bin_ieee754_flavor<T>::representation const& x)
45
+ {
46
+ if (!is_valid(x))
47
+ return std::numeric_limits<T>::quiet_NaN();
48
+
49
+ if (is_empty(x))
50
+ return std::numeric_limits<T>::infinity();
51
+
52
+ if (x.first == 0.0)
53
+ return -0.0;
54
+
55
+ return x.first;
56
+ }
57
+
58
+ // inf ( bare interval ) mixed type
59
+ template<typename T>
60
+ template<typename T_>
61
+ T
62
+ mpfr_bin_ieee754_flavor<T>::inf(mpfr_bin_ieee754_flavor<T>::representation_type<T_> const& x)
63
+ {
64
+ static_assert(std::numeric_limits<T_>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
65
+
66
+ if (!mpfr_bin_ieee754_flavor<T_>::is_valid(x))
67
+ return std::numeric_limits<T>::quiet_NaN();
68
+
69
+ // determine max. precision
70
+ typedef typename p1788::util::max_precision_type<T,T_>::type T_MAX;
71
+
72
+ // 1.) convert inputs to max precision; 2.) compute result in max precision; 3.) convert result to desired precision
73
+ // Error free for floating point inf-sup intervals due to outward rounding and downward rounding of the result
74
+ return convert_rndd(
75
+ mpfr_bin_ieee754_flavor<T_MAX>::inf(
76
+ mpfr_bin_ieee754_flavor<T_MAX>::convert_hull(x)
77
+ )
78
+ );
79
+ }
80
+
81
+ // inf ( decorated interval )
82
+ template<typename T>
83
+ T
84
+ mpfr_bin_ieee754_flavor<T>::inf(mpfr_bin_ieee754_flavor<T>::representation_dec const& x)
85
+ {
86
+ // call of bare version
87
+ return !is_valid(x) || is_nai(x) ? std::numeric_limits<T>::quiet_NaN() : inf(x.first);
88
+ }
89
+
90
+ // inf ( decorated interval ) mixed type
91
+ template<typename T>
92
+ template<typename T_>
93
+ T
94
+ mpfr_bin_ieee754_flavor<T>::inf(mpfr_bin_ieee754_flavor<T>::representation_dec_type<T_> const& x)
95
+ {
96
+ static_assert(std::numeric_limits<T_>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
97
+
98
+ // call of bare mixed type version
99
+ return !mpfr_bin_ieee754_flavor<T_>::is_valid(x) || mpfr_bin_ieee754_flavor<T_>::is_nai(x)
100
+ ? std::numeric_limits<T>::quiet_NaN()
101
+ : inf(x.first);
102
+ }
103
+
104
+ // sup ( bare interval )
105
+ template<typename T>
106
+ T
107
+ mpfr_bin_ieee754_flavor<T>::sup(mpfr_bin_ieee754_flavor<T>::representation const& x)
108
+ {
109
+ if (!is_valid(x))
110
+ return std::numeric_limits<T>::quiet_NaN();
111
+
112
+ if (is_empty(x))
113
+ return -std::numeric_limits<T>::infinity();
114
+
115
+ if (x.second == 0.0)
116
+ return +0.0;
117
+
118
+ return x.second;
119
+ }
120
+
121
+ // sup ( bare interval ) mixed type
122
+ template<typename T>
123
+ template<typename T_>
124
+ T
125
+ mpfr_bin_ieee754_flavor<T>::sup(mpfr_bin_ieee754_flavor<T>::representation_type<T_> const& x)
126
+ {
127
+ static_assert(std::numeric_limits<T_>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
128
+
129
+ if (!mpfr_bin_ieee754_flavor<T_>::is_valid(x))
130
+ return std::numeric_limits<T>::quiet_NaN();
131
+
132
+ // determine max. precision
133
+ typedef typename p1788::util::max_precision_type<T,T_>::type T_MAX;
134
+
135
+ // 1.) convert inputs to max precision; 2.) compute result in max precision; 3.) convert result to desired precision
136
+ // Error free for floating point inf-sup intervals due to outward rounding and upward rounding of the result
137
+ return convert_rndu(
138
+ mpfr_bin_ieee754_flavor<T_MAX>::sup(
139
+ mpfr_bin_ieee754_flavor<T_MAX>::convert_hull(x)
140
+ )
141
+ );
142
+ }
143
+
144
+ // sup ( decorated interval )
145
+ template<typename T>
146
+ T
147
+ mpfr_bin_ieee754_flavor<T>::sup(mpfr_bin_ieee754_flavor<T>::representation_dec const& x)
148
+ {
149
+ // call of bare version
150
+ return !is_valid(x) || is_nai(x) ? std::numeric_limits<T>::quiet_NaN() : sup(x.first);
151
+ }
152
+
153
+ // sup ( decorated interval ) mixed type
154
+ template<typename T>
155
+ template<typename T_>
156
+ T
157
+ mpfr_bin_ieee754_flavor<T>::sup(mpfr_bin_ieee754_flavor<T>::representation_dec_type<T_> const& x)
158
+ {
159
+ static_assert(std::numeric_limits<T_>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
160
+
161
+ // call of bare mixed type version
162
+ return !mpfr_bin_ieee754_flavor<T_>::is_valid(x) || mpfr_bin_ieee754_flavor<T_>::is_nai(x)
163
+ ? std::numeric_limits<T>::quiet_NaN()
164
+ : sup(x.first);
165
+ }
166
+
167
+
168
+
169
+
170
+ // mid ( bare interval )
171
+ template<typename T>
172
+ T
173
+ mpfr_bin_ieee754_flavor<T>::mid(mpfr_bin_ieee754_flavor<T>::representation const& x)
174
+ {
175
+ if (!is_valid(x) || is_empty(x))
176
+ return std::numeric_limits<T>::quiet_NaN();
177
+
178
+ if (is_entire(x))
179
+ return +0.0;
180
+
181
+ if (x.first == -std::numeric_limits<T>::infinity())
182
+ return -std::numeric_limits<T>::max();
183
+
184
+ if (x.second == std::numeric_limits<T>::infinity())
185
+ return std::numeric_limits<T>::max();
186
+
187
+
188
+ // extended EMIN for error free division by 2
189
+ typedef p1788::util::mpfr_var<mpfr_var::PREC,
190
+ mpfr_var::EMIN -1,
191
+ mpfr_var::EMAX,
192
+ false> ext_mpfr_var;
193
+
194
+ ext_mpfr_var::setup();
195
+
196
+ ext_mpfr_var xl(x.first, MPFR_RNDD);
197
+ ext_mpfr_var xu(x.second, MPFR_RNDU);
198
+
199
+ // error free because of the extended EMIN
200
+ mpfr_div_si(xl(),xl(),2, MPFR_RNDN);
201
+ mpfr_div_si(xu(),xu(),2, MPFR_RNDN);
202
+
203
+ int t = mpfr_add(xl(), xl(), xu(), MPFR_RNDN);
204
+
205
+ mpfr_var::setup();
206
+
207
+ xl.subnormalize(mpfr_check_range(xl(), t, MPFR_RNDN), MPFR_RNDN);
208
+
209
+ T res = xl.template get<T>(MPFR_RNDN);
210
+ return res == -0.0 ? +0.0 : res;
211
+ }
212
+
213
+ // mid ( bare interval ) mixed type
214
+ template<typename T>
215
+ template<typename T_>
216
+ T
217
+ mpfr_bin_ieee754_flavor<T>::mid(mpfr_bin_ieee754_flavor<T>::representation_type<T_> const& x)
218
+ {
219
+ // Same code as the non mixed type version. Only the type precision is adapted...
220
+ // Necessary to avoid double rounding???
221
+
222
+ static_assert(std::numeric_limits<T_>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
223
+
224
+ if (!mpfr_bin_ieee754_flavor<T_>::is_valid(x) || mpfr_bin_ieee754_flavor<T_>::is_empty(x))
225
+ return std::numeric_limits<T>::quiet_NaN();
226
+
227
+ if (mpfr_bin_ieee754_flavor<T_>::is_entire(x))
228
+ return +0.0;
229
+
230
+ if (x.first == -std::numeric_limits<T_>::infinity())
231
+ return -std::numeric_limits<T>::max();
232
+
233
+ if (x.second == std::numeric_limits<T_>::infinity())
234
+ return std::numeric_limits<T>::max();
235
+
236
+
237
+ // precision of T_ and extended EMIN for error free division by 2
238
+ typedef p1788::util::mpfr_var<mpfr_bin_ieee754_flavor<T_>::mpfr_var::PREC,
239
+ mpfr_bin_ieee754_flavor<T_>::mpfr_var::EMIN -1,
240
+ mpfr_bin_ieee754_flavor<T_>::mpfr_var::EMAX,
241
+ false> ext_mpfr_var;
242
+
243
+ ext_mpfr_var::setup();
244
+
245
+ ext_mpfr_var xl(x.first, MPFR_RNDD);
246
+ ext_mpfr_var xu(x.second, MPFR_RNDU);
247
+
248
+ // error free because of the extended EMIN
249
+ mpfr_div_si(xl(),xl(),2, MPFR_RNDN);
250
+ mpfr_div_si(xu(),xu(),2, MPFR_RNDN);
251
+
252
+
253
+ mpfr_var m;
254
+
255
+ // compute midpoint in precision of T
256
+ int t = mpfr_add(m(), xl(), xu(), MPFR_RNDN);
257
+
258
+ // Adjust ranges and subnormalize
259
+ mpfr_var::setup();
260
+ m.subnormalize(mpfr_check_range(m(), t, MPFR_RNDN), MPFR_RNDN);
261
+
262
+ T res = m.template get<T>(MPFR_RNDN);
263
+ return res == -0.0 ? +0.0 : res;
264
+ }
265
+
266
+ // mid ( decorated interval )
267
+ template<typename T>
268
+ T
269
+ mpfr_bin_ieee754_flavor<T>::mid(mpfr_bin_ieee754_flavor<T>::representation_dec const& x)
270
+ {
271
+ // call of bare version
272
+ return !is_valid(x) || is_nai(x) ? std::numeric_limits<T>::quiet_NaN() : mid(x.first);
273
+ }
274
+
275
+ // mid ( decorated interval ) mixed type
276
+ template<typename T>
277
+ template<typename T_>
278
+ T
279
+ mpfr_bin_ieee754_flavor<T>::mid(mpfr_bin_ieee754_flavor<T>::representation_dec_type<T_> const& x)
280
+ {
281
+ static_assert(std::numeric_limits<T_>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
282
+
283
+ // call of bare mixed type version
284
+ return !mpfr_bin_ieee754_flavor<T_>::is_valid(x) || mpfr_bin_ieee754_flavor<T_>::is_nai(x)
285
+ ? std::numeric_limits<T>::quiet_NaN()
286
+ : mid(x.first);
287
+ }
288
+
289
+
290
+
291
+
292
+
293
+ // rad ( bare interval )
294
+ template<typename T>
295
+ T
296
+ mpfr_bin_ieee754_flavor<T>::rad(mpfr_bin_ieee754_flavor<T>::representation const& x)
297
+ {
298
+ return mid_rad(x).second;
299
+ }
300
+
301
+ // rad ( bare interval ) mixed type
302
+ template<typename T>
303
+ template<typename T_>
304
+ T
305
+ mpfr_bin_ieee754_flavor<T>::rad(mpfr_bin_ieee754_flavor<T>::representation_type<T_> const& x)
306
+ {
307
+ static_assert(std::numeric_limits<T_>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
308
+
309
+ return mid_rad(x).second;
310
+ }
311
+
312
+ // rad ( decorated interval )
313
+ template<typename T>
314
+ T
315
+ mpfr_bin_ieee754_flavor<T>::rad(mpfr_bin_ieee754_flavor<T>::representation_dec const& x)
316
+ {
317
+ // call of bare version
318
+ return !is_valid(x) || is_nai(x) ? std::numeric_limits<T>::quiet_NaN() : rad(x.first);
319
+ }
320
+
321
+ // rad ( decorated interval ) mixed type
322
+ template<typename T>
323
+ template<typename T_>
324
+ T
325
+ mpfr_bin_ieee754_flavor<T>::rad(mpfr_bin_ieee754_flavor<T>::representation_dec_type<T_> const& x)
326
+ {
327
+ static_assert(std::numeric_limits<T_>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
328
+
329
+ // call of bare mixed type version
330
+ return !mpfr_bin_ieee754_flavor<T_>::is_valid(x) || mpfr_bin_ieee754_flavor<T_>::is_nai(x)
331
+ ? std::numeric_limits<T>::quiet_NaN()
332
+ : rad(x.first);
333
+ }
334
+
335
+
336
+
337
+
338
+ // mid_rad ( bare interval )
339
+ template<typename T>
340
+ std::pair<T, T>
341
+ mpfr_bin_ieee754_flavor<T>::mid_rad(mpfr_bin_ieee754_flavor<T>::representation const& x)
342
+ {
343
+ if (!is_valid(x) || is_empty(x))
344
+ return std::pair<T,T>(std::numeric_limits<T>::quiet_NaN(), std::numeric_limits<T>::quiet_NaN());
345
+
346
+ // compute mid point
347
+ std::pair<T,T> mr(mid(x), 0.0);
348
+
349
+ mpfr_var::setup();
350
+
351
+ mpfr_var m(mr.first, MPFR_RNDN);
352
+
353
+ mpfr_var xl(x.first, MPFR_RNDD);
354
+ mpfr_var xu(x.second, MPFR_RNDU);
355
+
356
+ // compute the maximum distance of the midpoint to the lower and the upper bound
357
+ // rad(x) = (xu - xl) / 2 does not guarantee that [mid(x) - rad(x), mid(x) + rad(x)] encloses x (if computed exactly)
358
+ mpfr_sub(xl(), m(), xl(), MPFR_RNDU);
359
+ mpfr_sub(xu(), xu(), m(), MPFR_RNDU);
360
+
361
+ mr.second = mpfr_cmp(xl(), xu()) > 0 ? xl.template get<T>(MPFR_RNDU) : xu.template get<T>(MPFR_RNDU);
362
+
363
+ if (mr.second == -0.0)
364
+ {
365
+ mr.second = +0.0;
366
+ }
367
+ return mr;
368
+ }
369
+
370
+ // mid_rad ( bare interval ) mixed type
371
+ template<typename T>
372
+ template<typename T_>
373
+ std::pair<T, T>
374
+ mpfr_bin_ieee754_flavor<T>::mid_rad(mpfr_bin_ieee754_flavor<T>::representation_type<T_> const& x)
375
+ {
376
+ // Same code as the non mixed type version. Only the rad precision is adapted...
377
+ // Necessary to guarantee that [mid(x) - rad(x), mid(x) + rad(x)] encloses x (if computed exactly)
378
+
379
+ static_assert(std::numeric_limits<T_>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
380
+
381
+ if (!mpfr_bin_ieee754_flavor<T_>::is_valid(x) || mpfr_bin_ieee754_flavor<T_>::is_empty(x) )
382
+ return std::pair<T,T>(std::numeric_limits<T>::quiet_NaN(), std::numeric_limits<T>::quiet_NaN());
383
+
384
+ // call of mixed type version of mid
385
+ std::pair<T,T> mr(mid(x), 0.0);
386
+
387
+ // determine max. precision
388
+ typedef typename p1788::util::max_precision_type<T,T_>::type T_MAX;
389
+ typedef typename mpfr_bin_ieee754_flavor<T_MAX>::mpfr_var mpfr_var_max;
390
+
391
+ mpfr_var_max::setup();
392
+
393
+ // Error free because T_MAX precision >= T precision
394
+ mpfr_var_max m(mr.first, MPFR_RNDN);
395
+ mpfr_var_max xl(x.first, MPFR_RNDD);
396
+ mpfr_var_max xu(x.second, MPFR_RNDU);
397
+
398
+ // compute the maximum distance of the midpoint to the lower and the upper bound
399
+ // rad(x) = (xu - xl) / 2 does not guarantee that [mid(x) - rad(x), mid(x) + rad(x)] encloses x (if computed exactly)
400
+ mpfr_sub(xl(), m(), xl(), MPFR_RNDU);
401
+ mpfr_sub(xu(), xu(), m(), MPFR_RNDU);
402
+
403
+ mr.second = mpfr_cmp(xl(), xu()) > 0 ? xl.template get<T>(MPFR_RNDU) : xu.template get<T>(MPFR_RNDU);
404
+
405
+ if (mr.second == -0.0)
406
+ {
407
+ mr.second = +0.0;
408
+ }
409
+ return mr;
410
+ }
411
+
412
+ // mid_rad ( decorated interval )
413
+ template<typename T>
414
+ std::pair<T, T>
415
+ mpfr_bin_ieee754_flavor<T>::mid_rad(mpfr_bin_ieee754_flavor<T>::representation_dec const& x)
416
+ {
417
+ // call of bare version
418
+ return !is_valid(x) || is_nai(x)
419
+ ? std::pair<T, T>(std::numeric_limits<T>::quiet_NaN(), std::numeric_limits<T>::quiet_NaN())
420
+ : mid_rad(x.first);
421
+ }
422
+
423
+
424
+ // mid_rad ( decorated interval ) mixed type
425
+ template<typename T>
426
+ template<typename T_>
427
+ std::pair<T, T>
428
+ mpfr_bin_ieee754_flavor<T>::mid_rad(mpfr_bin_ieee754_flavor<T>::representation_dec_type<T_> const& x)
429
+ {
430
+ static_assert(std::numeric_limits<T_>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
431
+
432
+ // call of bare mixed type version
433
+ return !mpfr_bin_ieee754_flavor<T_>::is_valid(x) || mpfr_bin_ieee754_flavor<T_>::is_nai(x)
434
+ ? std::pair<T, T>(std::numeric_limits<T>::quiet_NaN(), std::numeric_limits<T>::quiet_NaN())
435
+ : mid_rad(x.first);
436
+ }
437
+
438
+
439
+
440
+
441
+ // wid ( bare interval )
442
+ template<typename T>
443
+ T
444
+ mpfr_bin_ieee754_flavor<T>::wid(mpfr_bin_ieee754_flavor<T>::representation const& x)
445
+ {
446
+ if (!is_valid(x) || is_empty(x))
447
+ return std::numeric_limits<T>::quiet_NaN();
448
+
449
+ mpfr_var::setup();
450
+
451
+ mpfr_var xl(x.first, MPFR_RNDD);
452
+ mpfr_var xu(x.second, MPFR_RNDU);
453
+
454
+ xl.subnormalize(mpfr_sub(xl(), xu(), xl(), MPFR_RNDU), MPFR_RNDU);
455
+
456
+ T res = xl.template get<T>(MPFR_RNDU);
457
+ return res == -0.0 ? +0.0 : res;
458
+ }
459
+
460
+ // wid ( bare interval ) mixed type
461
+ template<typename T>
462
+ template<typename T_>
463
+ T
464
+ mpfr_bin_ieee754_flavor<T>::wid(mpfr_bin_ieee754_flavor<T>::representation_type<T_> const& x)
465
+ {
466
+ static_assert(std::numeric_limits<T_>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
467
+
468
+ if (!mpfr_bin_ieee754_flavor<T_>::is_valid(x))
469
+ return std::numeric_limits<T>::quiet_NaN();
470
+
471
+ // determine max. precision
472
+ typedef typename p1788::util::max_precision_type<T,T_>::type T_MAX;
473
+
474
+ // 1.) convert inputs to max precision; 2.) compute result in max precision; 3.) convert result to desired precision
475
+ // Error free for floating point inf-sup intervals due to outward rounding and upward rounding of the result
476
+ return convert_rndu(
477
+ mpfr_bin_ieee754_flavor<T_MAX>::wid(
478
+ mpfr_bin_ieee754_flavor<T_MAX>::convert_hull(x)
479
+ )
480
+ );
481
+ }
482
+
483
+ // wid ( decorated interval )
484
+ template<typename T>
485
+ T
486
+ mpfr_bin_ieee754_flavor<T>::wid(mpfr_bin_ieee754_flavor<T>::representation_dec const& x)
487
+ {
488
+ // call of bare version
489
+ return !is_valid(x) || is_nai(x) ? std::numeric_limits<T>::quiet_NaN() : wid(x.first);
490
+ }
491
+
492
+
493
+ // wid ( decorated interval ) mixed type
494
+ template<typename T>
495
+ template<typename T_>
496
+ T
497
+ mpfr_bin_ieee754_flavor<T>::wid(mpfr_bin_ieee754_flavor<T>::representation_dec_type<T_> const& x)
498
+ {
499
+ static_assert(std::numeric_limits<T_>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
500
+
501
+ // call of bare mixed type version
502
+ return !mpfr_bin_ieee754_flavor<T_>::is_valid(x) || mpfr_bin_ieee754_flavor<T_>::is_nai(x)
503
+ ? std::numeric_limits<T>::quiet_NaN()
504
+ : wid(x.first);
505
+ }
506
+
507
+
508
+
509
+
510
+ // mag ( bare interval )
511
+ template<typename T>
512
+ T
513
+ mpfr_bin_ieee754_flavor<T>::mag(mpfr_bin_ieee754_flavor<T>::representation const& x)
514
+ {
515
+ if (!is_valid(x) || is_empty(x))
516
+ return std::numeric_limits<T>::quiet_NaN();
517
+
518
+ T xl = std::abs(x.first);
519
+ T xu = std::abs(x.second);
520
+
521
+ return xl > xu ? xl : xu;
522
+ }
523
+
524
+
525
+ // mag ( bare interval ) mixed type
526
+ template<typename T>
527
+ template<typename T_>
528
+ T
529
+ mpfr_bin_ieee754_flavor<T>::mag(mpfr_bin_ieee754_flavor<T>::representation_type<T_> const& x)
530
+ {
531
+ static_assert(std::numeric_limits<T_>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
532
+
533
+ if (!mpfr_bin_ieee754_flavor<T_>::is_valid(x))
534
+ return std::numeric_limits<T>::quiet_NaN();
535
+
536
+ // determine max. precision
537
+ typedef typename p1788::util::max_precision_type<T,T_>::type T_MAX;
538
+
539
+ // 1.) convert inputs to max precision; 2.) compute result in max precision; 3.) convert result to desired precision
540
+ // Error free for floating point inf-sup intervals due to outward rounding and upward rounding of the result
541
+ return convert_rndu(
542
+ mpfr_bin_ieee754_flavor<T_MAX>::mag(
543
+ mpfr_bin_ieee754_flavor<T_MAX>::convert_hull(x)
544
+ )
545
+ );
546
+ }
547
+
548
+ // mag ( decorated interval )
549
+ template<typename T>
550
+ T
551
+ mpfr_bin_ieee754_flavor<T>::mag(mpfr_bin_ieee754_flavor<T>::representation_dec const& x)
552
+ {
553
+ // call of bare version
554
+ return !is_valid(x) || is_nai(x) ? std::numeric_limits<T>::quiet_NaN() : mag(x.first);
555
+ }
556
+
557
+
558
+ // mag ( decorated interval ) mixed type
559
+ template<typename T>
560
+ template<typename T_>
561
+ T
562
+ mpfr_bin_ieee754_flavor<T>::mag(mpfr_bin_ieee754_flavor<T>::representation_dec_type<T_> const& x)
563
+ {
564
+ static_assert(std::numeric_limits<T_>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
565
+
566
+ // call of bare mixed type version
567
+ return !mpfr_bin_ieee754_flavor<T_>::is_valid(x) || mpfr_bin_ieee754_flavor<T_>::is_nai(x)
568
+ ? std::numeric_limits<T>::quiet_NaN()
569
+ : mag(x.first);
570
+ }
571
+
572
+
573
+
574
+
575
+
576
+ // mig ( bare interval )
577
+ template<typename T>
578
+ T
579
+ mpfr_bin_ieee754_flavor<T>::mig(mpfr_bin_ieee754_flavor<T>::representation const& x)
580
+ {
581
+ if (!is_valid(x) || is_empty(x))
582
+ return std::numeric_limits<T>::quiet_NaN();
583
+
584
+ if (x.first < 0.0 && x.second > 0.0)
585
+ return +0.0;
586
+
587
+
588
+ T xl = std::abs(x.first);
589
+ T xu = std::abs(x.second);
590
+
591
+ return xl < xu ? xl : xu;
592
+ }
593
+
594
+ // mig ( bare interval ) mixed type
595
+ template<typename T>
596
+ template<typename T_>
597
+ T
598
+ mpfr_bin_ieee754_flavor<T>::mig(mpfr_bin_ieee754_flavor<T>::representation_type<T_> const& x)
599
+ {
600
+ static_assert(std::numeric_limits<T_>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
601
+
602
+ if (!mpfr_bin_ieee754_flavor<T_>::is_valid(x))
603
+ return std::numeric_limits<T>::quiet_NaN();
604
+
605
+ // determine max. precision
606
+ typedef typename p1788::util::max_precision_type<T,T_>::type T_MAX;
607
+
608
+ // 1.) convert inputs to max precision; 2.) compute result in max precision; 3.) convert result to desired precision
609
+ // Error free for floating point inf-sup intervals due to outward rounding and downward rounding of the result
610
+ T res = convert_rndd(
611
+ mpfr_bin_ieee754_flavor<T_MAX>::mig(
612
+ mpfr_bin_ieee754_flavor<T_MAX>::convert_hull(x)
613
+ )
614
+ );
615
+
616
+ // remove signbit (see convert_rndd)
617
+ return res == -0.0 ? +0.0 : res;
618
+ }
619
+
620
+ // mig ( decorated interval )
621
+ template<typename T>
622
+ T
623
+ mpfr_bin_ieee754_flavor<T>::mig(mpfr_bin_ieee754_flavor<T>::representation_dec const& x)
624
+ {
625
+ // call of bare version
626
+ return !is_valid(x) || is_nai(x) ? std::numeric_limits<T>::quiet_NaN() : mig(x.first);
627
+ }
628
+
629
+
630
+ // mig ( decorated interval ) mixed type
631
+ template<typename T>
632
+ template<typename T_>
633
+ T
634
+ mpfr_bin_ieee754_flavor<T>::mig(mpfr_bin_ieee754_flavor<T>::representation_dec_type<T_> const& x)
635
+ {
636
+ static_assert(std::numeric_limits<T_>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
637
+
638
+ // call of bare mixed type version
639
+ return !mpfr_bin_ieee754_flavor<T_>::is_valid(x) || mpfr_bin_ieee754_flavor<T_>::is_nai(x)
640
+ ? std::numeric_limits<T>::quiet_NaN()
641
+ : mig(x.first);
642
+ }
643
+
644
+
645
+
646
+ } // namespace setbased
647
+
648
+ } // namespace infsup
649
+
650
+ } // namespace flavor
651
+
652
+ } // namespace p1788
653
+
654
+
655
+ #endif // LIBIEEEP1788_P1788_FLAVOR_INFSUP_SETBASED_MPFR_BIN_IEEE754_FLAVOR_NUM_FUNC_IMPL_HPP