@@ -466,7 +466,7 @@ struct mpfr_float_imp<digits10, allocate_dynamic>
466466 }
467467 static std::atomic<variable_precision_options>& get_global_default_options ()noexcept
468468 {
469- static std::atomic<variable_precision_options> val{ variable_precision_options::preserve_source_precision | variable_precision_options::ignore_alian_types };
469+ static std::atomic<variable_precision_options> val{ variable_precision_options::preserve_source_precision | variable_precision_options::ignore_alien_types };
470470 return val;
471471 }
472472 static variable_precision_options& get_default_options ()noexcept
@@ -911,12 +911,12 @@ struct mpfr_float_backend<0, allocate_dynamic> : public detail::mpfr_float_imp<0
911911{
912912 mpfr_float_backend () : detail::mpfr_float_imp<0 , allocate_dynamic>() {}
913913 mpfr_float_backend (const mpfr_t val)
914- : detail::mpfr_float_imp<0 , allocate_dynamic>(( unsigned )mpfr_get_prec(val))
914+ : detail::mpfr_float_imp<0 , allocate_dynamic>(preserve_source_precision() ? ( unsigned )mpfr_get_prec(val) : boost::multiprecision::detail::digits10_2_2(get_default_precision() ))
915915 {
916916 mpfr_set (this ->m_data , val, GMP_RNDN);
917917 }
918918 mpfr_float_backend (const mpf_t val)
919- : detail::mpfr_float_imp<0 , allocate_dynamic>(( unsigned )mpf_get_prec(val))
919+ : detail::mpfr_float_imp<0 , allocate_dynamic>(preserve_source_precision() ? ( unsigned )mpf_get_prec(val) : boost::multiprecision::detail::digits10_2_2(get_default_precision() ))
920920 {
921921 mpfr_set_f (this ->m_data , val, GMP_RNDN);
922922 }
@@ -962,13 +962,13 @@ struct mpfr_float_backend<0, allocate_dynamic> : public detail::mpfr_float_imp<0
962962 }
963963 template <unsigned D>
964964 mpfr_float_backend (const mpfr_float_backend<D>& val)
965- : detail::mpfr_float_imp<0 , allocate_dynamic>(mpfr_get_prec(val.data()))
965+ : detail::mpfr_float_imp<0 , allocate_dynamic>(preserve_source_precision() ? mpfr_get_prec(val.data()) : boost::multiprecision::detail::digits10_2_2(get_default_precision ()))
966966 {
967967 mpfr_set (this ->m_data , val.data (), GMP_RNDN);
968968 }
969969 template <unsigned D>
970970 mpfr_float_backend (const gmp_float<D>& val)
971- : detail::mpfr_float_imp<0 , allocate_dynamic>(mpf_get_prec(val.data()))
971+ : detail::mpfr_float_imp<0 , allocate_dynamic>(preserve_source_precision() ? mpf_get_prec(val.data()) : boost::multiprecision::detail::digits10_2_2(get_default_precision ()))
972972 {
973973 mpfr_set_f (this ->m_data , val.data (), GMP_RNDN);
974974 }
@@ -996,17 +996,17 @@ struct mpfr_float_backend<0, allocate_dynamic> : public detail::mpfr_float_imp<0
996996 mpfr_float_backend& operator =(const mpfr_t val)
997997 {
998998 if (this ->m_data [0 ]._mpfr_d == 0 )
999- mpfr_init2 (this ->m_data , mpfr_get_prec (val));
1000- else
999+ mpfr_init2 (this ->m_data , preserve_source_precision () ? mpfr_get_prec (val) : boost::multiprecision::detail::digits10_2_2 ( get_default_precision () ));
1000+ else if ( preserve_source_precision ())
10011001 mpfr_set_prec (this ->m_data , mpfr_get_prec (val));
10021002 mpfr_set (this ->m_data , val, GMP_RNDN);
10031003 return *this ;
10041004 }
10051005 mpfr_float_backend& operator =(const mpf_t val)
10061006 {
10071007 if (this ->m_data [0 ]._mpfr_d == 0 )
1008- mpfr_init2 (this ->m_data , ( mpfr_prec_t )mpf_get_prec (val));
1009- else
1008+ mpfr_init2 (this ->m_data , preserve_source_precision () ? ( mpfr_prec_t )mpf_get_prec (val) : boost::multiprecision::detail::digits10_2_2 ( get_default_precision () ));
1009+ else if ( preserve_source_precision ())
10101010 mpfr_set_prec (this ->m_data , (unsigned )mpf_get_prec (val));
10111011 mpfr_set_f (this ->m_data , val, GMP_RNDN);
10121012 return *this ;
@@ -1029,8 +1029,8 @@ struct mpfr_float_backend<0, allocate_dynamic> : public detail::mpfr_float_imp<0
10291029 mpfr_float_backend& operator =(const mpfr_float_backend<D>& val)
10301030 {
10311031 if (this ->m_data [0 ]._mpfr_d == 0 )
1032- mpfr_init2 (this ->m_data , mpfr_get_prec (val.data ()));
1033- else
1032+ mpfr_init2 (this ->m_data , preserve_source_precision () ? mpfr_get_prec (val.data ()) : boost::multiprecision::detail::digits10_2_2 ( get_default_precision ()));
1033+ else if ( preserve_source_precision ())
10341034 mpfr_set_prec (this ->m_data , mpfr_get_prec (val.data ()));
10351035 mpfr_set (this ->m_data , val.data (), GMP_RNDN);
10361036 return *this ;
@@ -1039,8 +1039,8 @@ struct mpfr_float_backend<0, allocate_dynamic> : public detail::mpfr_float_imp<0
10391039 mpfr_float_backend& operator =(const gmp_float<D>& val)
10401040 {
10411041 if (this ->m_data [0 ]._mpfr_d == 0 )
1042- mpfr_init2 (this ->m_data , mpf_get_prec (val.data ()));
1043- else
1042+ mpfr_init2 (this ->m_data , preserve_source_precision () ? mpf_get_prec (val.data ()) : boost::multiprecision::detail::digits10_2_2 ( get_default_precision ()));
1043+ else if ( preserve_source_precision ())
10441044 mpfr_set_prec (this ->m_data , mpf_get_prec (val.data ()));
10451045 mpfr_set_f (this ->m_data , val.data (), GMP_RNDN);
10461046 return *this ;
@@ -1102,6 +1102,10 @@ struct mpfr_float_backend<0, allocate_dynamic> : public detail::mpfr_float_imp<0
11021102 {
11031103 get_default_options () = (get_default_options () & ~group) | opts;
11041104 }
1105+ static bool preserve_source_precision ()
1106+ {
1107+ return (get_default_options () & variable_precision_options::precision_group) == variable_precision_options::preserve_source_precision;
1108+ }
11051109};
11061110
11071111template <unsigned digits10, mpfr_allocation_type AllocationType, class T >
0 commit comments