Skip to content

Commit ec8679d

Browse files
committed
Correct read over-large strings and sqrt(INF)
1 parent 68b889a commit ec8679d

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

include/boost/multiprecision/cpp_double_fp.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,11 @@ bool cpp_double_fp_backend<FloatingPointType>::rd_string(const char* pstr)
10791079

10801080
if (is_definitely_inf)
10811081
{
1082+
const bool b_neg { f_dec.isneg() };
1083+
10821084
static_cast<void>(operator=(local_double_fp_type::my_value_inf()));
1085+
1086+
if (b_neg) { negate(); }
10831087
}
10841088
else
10851089
{
@@ -1394,9 +1398,9 @@ constexpr void eval_sqrt(cpp_double_fp_backend<FloatingPointType>& result, const
13941398
using double_float_type = cpp_double_fp_backend<FloatingPointType>;
13951399
using local_float_type = typename double_float_type::float_type;
13961400

1397-
const auto fpc = eval_fpclassify(o);
1401+
const int fpc { eval_fpclassify(o) };
13981402

1399-
const auto isneg_o = o.isneg();
1403+
const bool isneg_o { o.isneg() };
14001404

14011405
if ((fpc != FP_NORMAL) || isneg_o)
14021406
{
@@ -1405,14 +1409,14 @@ constexpr void eval_sqrt(cpp_double_fp_backend<FloatingPointType>& result, const
14051409
result = double_float_type(0);
14061410
return;
14071411
}
1408-
else if (fpc == FP_NAN)
1412+
else if ((fpc == FP_NAN) || isneg_o)
14091413
{
14101414
result = double_float_type::my_value_nan();
14111415
return;
14121416
}
1413-
else if ((fpc == FP_INFINITE) || isneg_o)
1417+
else if (fpc == FP_INFINITE)
14141418
{
1415-
result = double_float_type::my_value_nan();
1419+
result = double_float_type::my_value_inf();
14161420
return;
14171421
}
14181422
}

test/test_arithmetic.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,11 @@ void test_float_funcs(const std::integral_constant<bool, true>&)
12131213
a = 4;
12141214
a = sqrt(a);
12151215
BOOST_CHECK_CLOSE_FRACTION(a, 2, tol);
1216+
BOOST_IF_CONSTEXPR(std::numeric_limits<Real>::is_specialized && std::numeric_limits<Real>::has_infinity)
1217+
{
1218+
a = std::numeric_limits<Real>::infinity();
1219+
BOOST_CHECK((boost::math::isinf)(a));
1220+
}
12161221
a = 3;
12171222
a = exp(a);
12181223
BOOST_CHECK_CLOSE_FRACTION(a, Real(exp(Real(3))), tol);

0 commit comments

Comments
 (0)