Skip to content

Commit b42d427

Browse files
committed
Backend extreme division handling
1 parent ef23b06 commit b42d427

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

include/boost/multiprecision/cpp_double_fp.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,39 @@ class cpp_double_fp_backend
680680

681681
float_type u { cpp_df_qf_detail::split(float_type()) * v.data.first };
682682

683+
if (cpp_df_qf_detail::ccmath::isinf(u))
684+
{
685+
// Evidently we have a very large denominator. Let's take a last chance
686+
// for finite division. Use the ratio of square roots and subsequently
687+
// square the ratio, handling the sign of the result separately.
688+
689+
const bool u_neg { isneg() };
690+
const bool v_neg { v.isneg() };
691+
const bool b_neg { u_neg != v_neg };
692+
693+
cpp_double_fp_backend uu { *this };
694+
cpp_double_fp_backend vv { v };
695+
696+
cpp_double_fp_backend sqrt_u { };
697+
cpp_double_fp_backend sqrt_v { };
698+
699+
if(u_neg) { uu.negate(); }
700+
if(v_neg) { vv.negate(); }
701+
702+
eval_sqrt(sqrt_u, uu);
703+
eval_sqrt(sqrt_v, vv);
704+
705+
cpp_double_fp_backend sqrt_ratio { sqrt_u / sqrt_v };
706+
707+
*this = sqrt_ratio;
708+
709+
eval_multiply(*this, sqrt_ratio);
710+
711+
if (b_neg)
712+
negate();
713+
return *this;
714+
}
715+
683716
const float_type hc { c - float_type { c - C } };
684717

685718
const float_type hv { u - float_type { u - v.data.first } };

0 commit comments

Comments
 (0)