Update complex_adaptor to match precision requirements.

Add test case.
Fixes https://github.com/boostorg/multiprecision/issues/595
This commit is contained in:
jzmaddock
2024-02-09 17:17:59 +00:00
parent de240992c3
commit 467f09cab2
3 changed files with 97 additions and 0 deletions
@@ -192,6 +192,56 @@ struct complex_adaptor
m_real.negate();
m_imag.negate();
}
//
// Default precision:
//
static BOOST_MP_CXX14_CONSTEXPR unsigned default_precision() noexcept
{
return Backend::default_precision();
}
static BOOST_MP_CXX14_CONSTEXPR void default_precision(unsigned digits10)
{
Backend::default_precision(digits10);
Backend::thread_default_precision(digits10);
}
static BOOST_MP_CXX14_CONSTEXPR unsigned thread_default_precision() noexcept
{
return Backend::thread_default_precision();
}
static BOOST_MP_CXX14_CONSTEXPR void thread_default_precision(unsigned digits10)
{
Backend::thread_default_precision(digits10);
}
BOOST_MP_CXX14_CONSTEXPR unsigned precision() const noexcept
{
return m_real.precision();
}
BOOST_MP_CXX14_CONSTEXPR void precision(unsigned digits10)
{
m_real.precision(digits10);
m_imag.precision(digits10);
}
//
// Variable precision options:
//
static constexpr variable_precision_options default_variable_precision_options()noexcept
{
return Backend::default_variable_precision_options();
}
static constexpr variable_precision_options thread_default_variable_precision_options()noexcept
{
return Backend::thread_default_variable_precision_options();
}
static BOOST_MP_CXX14_CONSTEXPR void default_variable_precision_options(variable_precision_options opts)
{
Backend::default_variable_precision_options(opts);
Backend::thread_default_variable_precision_options(opts);
}
static BOOST_MP_CXX14_CONSTEXPR void thread_default_variable_precision_options(variable_precision_options opts)
{
Backend::thread_default_variable_precision_options(opts);
}
};
template <class Backend, class T>
+1
View File
@@ -1234,6 +1234,7 @@ test-suite misc :
[ run git_issue_540.cpp ]
[ run git_issue_573.cpp : : : <toolset>msvc:<cxxflags>-sdl ]
[ run git_issue_576.cpp : : : [ check-target-builds ../config//has_float128 : <define>TEST_FLOAT128 <source>quadmath : ] ]
[ run git_issue_595.cpp : : : [ check-target-builds ../config//has_mpfr : <source>gmp <source>mpfr ] ]
[ compile git_issue_98.cpp :
[ check-target-builds ../config//has_float128 : <define>TEST_FLOAT128 <source>quadmath : ]
[ check-target-builds ../config//has_gmp : <define>TEST_GMP <source>gmp : ]
+46
View File
@@ -0,0 +1,46 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2023 John Maddock. Distributed under 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)
#include <boost/multiprecision/mpfr.hpp>
#include <boost/multiprecision/complex_adaptor.hpp>
#include <boost/multiprecision/logged_adaptor.hpp>
#include <boost/multiprecision/debug_adaptor.hpp>
#include <iostream>
#include "test.hpp"
template <class T>
void test()
{
T val;
unsigned n = T::default_precision();
T::default_precision(n);
n = T::thread_default_precision();
T::thread_default_precision(n);
n = val.precision();
val.precision(n);
}
int main()
{
using namespace boost::multiprecision;
test<mpfr_float>();
using c = number<complex_adaptor<mpfr_float::backend_type>, et_on>;
test<c>();
using l = number<logged_adaptor<mpfr_float::backend_type>, et_on>;
test<l>();
using d = number<debug_adaptor<mpfr_float::backend_type>, et_on>;
test<d>();
return boost::report_errors();
}