Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update complex_adaptor to match precision requirements. #597

Merged
merged 2 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions include/boost/multiprecision/complex_adaptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -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 : <build>no ] ]
[ 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 : ]
Expand Down
46 changes: 46 additions & 0 deletions test/git_issue_595.cpp
Original file line number Diff line number Diff line change
@@ -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();
}
Loading