summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/math/minimax/multiprecision.hpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/math/minimax/multiprecision.hpp
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/math/minimax/multiprecision.hpp')
-rw-r--r--src/boost/libs/math/minimax/multiprecision.hpp224
1 files changed, 224 insertions, 0 deletions
diff --git a/src/boost/libs/math/minimax/multiprecision.hpp b/src/boost/libs/math/minimax/multiprecision.hpp
new file mode 100644
index 00000000..2f44ac07
--- /dev/null
+++ b/src/boost/libs/math/minimax/multiprecision.hpp
@@ -0,0 +1,224 @@
+// (C) Copyright John Maddock 2015.
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_REMEZ_MULTIPRECISION_HPP
+#define BOOST_REMEZ_MULTIPRECISION_HPP
+
+#include <boost/multiprecision/cpp_bin_float.hpp>
+
+#ifdef USE_NTL
+#include <boost/math/bindings/rr.hpp>
+namespace std {
+ using boost::math::ntl::pow;
+} // workaround for spirit parser.
+
+typedef boost::math::ntl::RR mp_type;
+
+inline void set_working_precision(int n)
+{
+ NTL::RR::SetPrecision(working_precision);
+}
+
+inline int get_working_precision()
+{
+ return mp_type::precision(working_precision);
+}
+
+inline void set_output_precision(int n)
+{
+ NTL::RR::SetOutputPrecision(n);
+}
+
+inline mp_type round_to_precision(mp_type m, int bits)
+{
+ return NTL::RoundToPrecision(m.value(), bits);
+}
+
+
+namespace boost {
+ namespace math {
+ namespace tools {
+
+ template <>
+ inline boost::multiprecision::cpp_bin_float_double_extended real_cast<boost::multiprecision::cpp_bin_float_double_extended, mp_type>(mp_type val)
+ {
+ unsigned p = NTL::RR::OutputPrecision();
+ NTL::RR::SetOutputPrecision(20);
+ boost::multiprecision::cpp_bin_float_double_extended r = boost::lexical_cast<boost::multiprecision::cpp_bin_float_double_extended>(val);
+ NTL::RR::SetOutputPrecision(p);
+ return r;
+ }
+ template <>
+ inline boost::multiprecision::cpp_bin_float_quad real_cast<boost::multiprecision::cpp_bin_float_quad, mp_type>(mp_type val)
+ {
+ unsigned p = NTL::RR::OutputPrecision();
+ NTL::RR::SetOutputPrecision(35);
+ boost::multiprecision::cpp_bin_float_quad r = boost::lexical_cast<boost::multiprecision::cpp_bin_float_quad>(val);
+ NTL::RR::SetOutputPrecision(p);
+ return r;
+ }
+
+ }
+ }
+}
+
+#elif defined(USE_CPP_BIN_FLOAT_100)
+
+#include <boost/multiprecision/cpp_bin_float.hpp>
+
+typedef boost::multiprecision::cpp_bin_float_100 mp_type;
+
+inline void set_working_precision(int n)
+{
+}
+
+inline void set_output_precision(int n)
+{
+ std::cout << std::setprecision(n);
+ std::cerr << std::setprecision(n);
+}
+
+inline mp_type round_to_precision(mp_type m, int bits)
+{
+ int i;
+ mp_type f = frexp(m, &i);
+ f = ldexp(f, bits);
+ i -= bits;
+ f = floor(f);
+ return ldexp(f, i);
+}
+
+inline int get_working_precision()
+{
+ return std::numeric_limits<mp_type>::digits;
+}
+
+namespace boost {
+ namespace math {
+ namespace tools {
+
+ template <>
+ inline boost::multiprecision::cpp_bin_float_double_extended real_cast<boost::multiprecision::cpp_bin_float_double_extended, mp_type>(mp_type val)
+ {
+ return boost::multiprecision::cpp_bin_float_double_extended(val);
+ }
+ template <>
+ inline boost::multiprecision::cpp_bin_float_quad real_cast<boost::multiprecision::cpp_bin_float_quad, mp_type>(mp_type val)
+ {
+ return boost::multiprecision::cpp_bin_float_quad(val);
+ }
+
+ }
+ }
+}
+
+
+#elif defined(USE_MPFR_100)
+
+#include <boost/multiprecision/mpfr.hpp>
+
+typedef boost::multiprecision::mpfr_float_100 mp_type;
+
+inline void set_working_precision(int n)
+{
+}
+
+inline void set_output_precision(int n)
+{
+ std::cout << std::setprecision(n);
+ std::cerr << std::setprecision(n);
+}
+
+inline mp_type round_to_precision(mp_type m, int bits)
+{
+ mpfr_prec_round(m.backend().data(), bits, MPFR_RNDN);
+ return m;
+}
+
+inline int get_working_precision()
+{
+ return std::numeric_limits<mp_type>::digits;
+}
+
+namespace boost {
+ namespace math {
+ namespace tools {
+
+ template <>
+ inline boost::multiprecision::cpp_bin_float_double_extended real_cast<boost::multiprecision::cpp_bin_float_double_extended, mp_type>(mp_type val)
+ {
+ return boost::multiprecision::cpp_bin_float_double_extended(val);
+ }
+ template <>
+ inline boost::multiprecision::cpp_bin_float_quad real_cast<boost::multiprecision::cpp_bin_float_quad, mp_type>(mp_type val)
+ {
+ return boost::multiprecision::cpp_bin_float_quad(val);
+ }
+
+ }
+ }
+}
+
+
+#else
+
+#include <boost/multiprecision/mpfr.hpp>
+
+typedef boost::multiprecision::mpfr_float mp_type;
+
+inline void set_working_precision(int n)
+{
+ boost::multiprecision::mpfr_float::default_precision(boost::multiprecision::detail::digits2_2_10(n));
+}
+
+inline void set_output_precision(int n)
+{
+ std::cout << std::setprecision(n);
+ std::cerr << std::setprecision(n);
+}
+
+inline mp_type round_to_precision(mp_type m, int bits)
+{
+ mpfr_prec_round(m.backend().data(), bits, MPFR_RNDN);
+ return m;
+}
+
+inline int get_working_precision()
+{
+ return mp_type::default_precision();
+}
+
+namespace boost {
+ namespace math {
+ namespace tools {
+
+ template <>
+ inline boost::multiprecision::cpp_bin_float_double_extended real_cast<boost::multiprecision::cpp_bin_float_double_extended, mp_type>(mp_type val)
+ {
+ return boost::multiprecision::cpp_bin_float_double_extended(val);
+ }
+ template <>
+ inline boost::multiprecision::cpp_bin_float_quad real_cast<boost::multiprecision::cpp_bin_float_quad, mp_type>(mp_type val)
+ {
+ return boost::multiprecision::cpp_bin_float_quad(val);
+ }
+
+ }
+ }
+}
+
+
+
+#endif
+
+
+
+
+#endif // BOOST_REMEZ_MULTIPRECISION_HPP
+
+
+
+
+