Skip to content

Commit

Permalink
Merge pull request #597 from boostorg/issue595
Browse files Browse the repository at this point in the history
Update complex_adaptor to match precision requirements.
  • Loading branch information
jzmaddock authored Feb 10, 2024
2 parents 4038c77 + d9bb0dd commit 2766661
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
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();
}

0 comments on commit 2766661

Please sign in to comment.