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.
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,140 @@
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_MIXED_TYPE_TRAITS_HPP
24
+ #define LIBIEEEP1788_P1788_UTIL_MIXED_TYPE_TRAITS_HPP
25
+
26
+ #include <type_traits>
27
+
28
+ #include "p1788/infsup/forward_declaration.hpp"
29
+
30
+ namespace p1788
31
+ {
32
+
33
+ namespace util
34
+ {
35
+
36
+
37
+
38
+ // \brief Trait to determine the precision oder of the type T
39
+ //
40
+ // The order should be realized by an enum class for each group of coherent
41
+ // types, e.g. IEEE 754 binary floating point {float, double, long double}.
42
+ // Hence, only types of the same group are comparable.
43
+ //
44
+ // \param T type
45
+ // \return field value contains the order
46
+ //
47
+ //
48
+ template<typename T>
49
+ class type_precision_order
50
+ : public std::integral_constant<int, 0>
51
+ {
52
+ static_assert(!std::is_same<T,T>::value,
53
+ "Type is not supported!");
54
+ };
55
+
56
+
57
+
58
+
59
+ template<typename... Types> class max_precision_type
60
+ {
61
+ static_assert(sizeof...(Types) > 0,
62
+ "max_precision_interval_type for an empty argument list!");
63
+ };
64
+
65
+
66
+ template<typename First, typename Second, typename... Tail>
67
+ class max_precision_type<First, Second, Tail...>
68
+ {
69
+ public:
70
+ static_assert(std::is_same<typename type_precision_order<First>::value_type,
71
+ typename type_precision_order<Second>::value_type>::value,
72
+ "Different type groups!");
73
+
74
+ typedef typename max_precision_type<
75
+ typename std::conditional<
76
+ (type_precision_order<First>::value > type_precision_order<Second>::value),
77
+ First,
78
+ Second
79
+ >::type,
80
+ Tail...
81
+ >::type type;
82
+ };
83
+
84
+ template<typename Type>
85
+ class max_precision_type<Type>
86
+ {
87
+ public:
88
+ typedef Type type;
89
+ };
90
+
91
+
92
+
93
+
94
+
95
+
96
+ //------------------------------------------------------------------------------
97
+ // IEEE 754 Binary specialization for type_precision_order
98
+ //------------------------------------------------------------------------------
99
+
100
+ enum class ieee754_binary_precision_order : unsigned int
101
+ {
102
+ float_type,
103
+ double_type,
104
+ long_double_type
105
+ };
106
+
107
+
108
+ // Ignore the warning about non-virtual destructors
109
+ // on GCC push the last diagnostic state and disable -Weffc++
110
+ //TODO support other compiler
111
+ #pragma GCC diagnostic push
112
+ #pragma GCC diagnostic ignored "-Weffc++"
113
+
114
+ template<>
115
+ class type_precision_order<float>
116
+ : public std::integral_constant<ieee754_binary_precision_order,
117
+ ieee754_binary_precision_order::float_type>
118
+ { };
119
+
120
+ template<>
121
+ class type_precision_order<double>
122
+ : public std::integral_constant<ieee754_binary_precision_order,
123
+ ieee754_binary_precision_order::double_type>
124
+ { };
125
+
126
+ template<>
127
+ class type_precision_order<long double>
128
+ : public std::integral_constant<ieee754_binary_precision_order,
129
+ ieee754_binary_precision_order::long_double_type>
130
+ { };
131
+
132
+ // on GCC enable the diagnostic state -Weffc++ again
133
+ #pragma GCC diagnostic pop
134
+
135
+
136
+ } // namespace util
137
+
138
+ } // namespace p1788
139
+
140
+ #endif // LIBIEEEP1788_P1788_UTIL_MIXED_TYPE_TRAITS_HPP
@@ -0,0 +1,77 @@
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_EFT_HPP
24
+ #define LIBIEEEP1788_P1788_UTIL_EFT_HPP
25
+
26
+ #include <utility>
27
+
28
+ #include "p1788/util/mpfr_var.hpp"
29
+
30
+ namespace p1788
31
+ {
32
+
33
+ namespace util
34
+ {
35
+
36
+ template<typename T>
37
+ inline std::pair<T,T> two_sum(T const& a, T const& b)
38
+ {
39
+ static_assert(std::numeric_limits<T>::is_iec559, "Only IEEE 754 binary compliant types are supported!");
40
+
41
+ // Typedef for the corresponding mpfr wrapper class representing the IEEE 754 binary floating point format of type T
42
+ typedef p1788::util::mpfr_var<
43
+ std::numeric_limits<T>::digits,
44
+ std::numeric_limits<T>::has_denorm != std::denorm_present ? std::numeric_limits<T>::min_exponent
45
+ : std::numeric_limits<T>::min_exponent - std::numeric_limits<T>::digits + 1,
46
+ std::numeric_limits<T>::max_exponent,
47
+ std::numeric_limits<T>::has_denorm == std::denorm_present
48
+ > mpfr_var;
49
+
50
+ mpfr_var::setup();
51
+
52
+ mpfr_var a_(a, MPFR_RNDN);
53
+ mpfr_var b_(b, MPFR_RNDN);
54
+
55
+ mpfr_var s;
56
+ mpfr_var a_delta;
57
+ mpfr_var b_delta;
58
+
59
+ s.subnormalize(mpfr_add(s(), a_(), b_(), MPFR_RNDN), MPFR_RNDN);
60
+ a_delta.subnormalize(mpfr_sub(a_delta(), s(), b_(), MPFR_RNDN), MPFR_RNDN);
61
+ b_delta.subnormalize(mpfr_sub(b_delta(), s(), a_delta(), MPFR_RNDN), MPFR_RNDN);
62
+
63
+ a_delta.subnormalize(mpfr_sub(a_delta(), a_(), a_delta(), MPFR_RNDN), MPFR_RNDN);
64
+ b_delta.subnormalize(mpfr_sub(b_delta(), b_(), b_delta(), MPFR_RNDN), MPFR_RNDN);
65
+
66
+ a_delta.subnormalize(mpfr_add(a_delta(), a_delta(), b_delta(), MPFR_RNDN), MPFR_RNDN);
67
+
68
+ return std::pair<T,T>(s.template get<T>(MPFR_RNDN), a_delta.template get<T>(MPFR_RNDN));
69
+ }
70
+
71
+
72
+
73
+ } // namespace util
74
+
75
+ } // namespace p1788
76
+
77
+ #endif // LIBIEEEP1788_P1788_UTIL_EFT_HPP
@@ -0,0 +1,119 @@
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_UTIL_MPFR_VAR_HPP
27
+ #define LIBIEEEP1788_P1788_UTIL_MPFR_VAR_HPP
28
+
29
+ #define MPFR_USE_INTMAX_T
30
+
31
+ #include <mpfr.h>
32
+ #include <string>
33
+
34
+ #include "p1788/io/io_manip.hpp"
35
+
36
+ //------------------------------------------------------------------------------
37
+ // Generic wrapper for MPFR mpfr_t types
38
+ //------------------------------------------------------------------------------
39
+
40
+ namespace p1788
41
+ {
42
+
43
+ namespace util
44
+ {
45
+
46
+ // Wrapper class for mpfr_t
47
+ template<mpfr_prec_t PREC_, mpfr_exp_t EMIN_, mpfr_exp_t EMAX_, bool SUBNORMALIZE_>
48
+ class mpfr_var
49
+ {
50
+ // Check range
51
+ static_assert(PREC_ > 0, "PREC_ is not greater then 0!");
52
+ static_assert(EMIN_ < 0, "EMIN_ is not less than 0!");
53
+ static_assert(EMAX_ > 0, "EMAX_ is not less than 0!");
54
+
55
+ public:
56
+
57
+ static const mpfr_prec_t PREC = PREC_;
58
+ static const mpfr_exp_t EMIN = EMIN_;
59
+ static const mpfr_exp_t EMAX = EMAX_;
60
+ static const bool SUBNORMALIZE = SUBNORMALIZE_;
61
+
62
+ // initialze mpfr system
63
+ static void setup();
64
+
65
+ // clears mpfr cache
66
+ static void free_cache();
67
+
68
+ // Constructors - initialize mpfr_t var with corresponding value using the rounding mode rnd
69
+ mpfr_var();
70
+
71
+ mpfr_var(unsigned long int op, mpfr_rnd_t rnd);
72
+ mpfr_var(long int op, mpfr_rnd_t rnd);
73
+ mpfr_var(float op, mpfr_rnd_t rnd);
74
+ mpfr_var(double op, mpfr_rnd_t rnd);
75
+ mpfr_var(long double op, mpfr_rnd_t rnd);
76
+
77
+ // Destructor
78
+ ~mpfr_var();
79
+
80
+ // writes corresponding value to mpfr_t var using the rounding mode rnd
81
+ void set(unsigned long int op, mpfr_rnd_t rnd);
82
+ void set(long int op, mpfr_rnd_t rnd);
83
+ void set(float op, mpfr_rnd_t rnd);
84
+ void set(double op, mpfr_rnd_t rnd);
85
+ void set(long double op, mpfr_rnd_t rnd);
86
+
87
+ // Generic getter - it is possible to round the value to a preferred type using the rounding mode rnd
88
+ template<typename T>
89
+ T get(mpfr_rnd_t rnd);
90
+
91
+ // Returns a string representation
92
+ // It is possible to specify the outputformat
93
+ std::string get_str(mpfr_rnd_t rnd,
94
+ p1788::io::number_representation_flags rep,
95
+ size_t width,
96
+ size_t precision,
97
+ p1788::io::text_representation_flags text_rep);
98
+
99
+ // Reference to the underlying mpfr_t
100
+ mpfr_t& operator() ();
101
+ mpfr_t const& operator() () const;
102
+
103
+ // subnormalization
104
+ int subnormalize(int t, mpfr_rnd_t rnd);
105
+
106
+ private:
107
+ mpfr_t var_;
108
+
109
+ };
110
+
111
+
112
+ } // namespace util
113
+
114
+ } // namespace p1788
115
+
116
+
117
+ #include "p1788/util/mpfr_var_impl.hpp"
118
+
119
+ #endif // LIBIEEEP1788_P1788_UTIL_MPFR_VAR_HPP