Skip to content

Commit

Permalink
Restore test_exp also subnormals in add/sub
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed Dec 20, 2024
1 parent b42d427 commit c348685
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
24 changes: 20 additions & 4 deletions include/boost/multiprecision/cpp_double_fp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,20 @@ class cpp_double_fp_backend
return *this;
}

const auto iszero_u = (fpc_u == FP_ZERO);
const auto iszero_u = ((fpc_u == FP_ZERO) || (fpc_u == FP_SUBNORMAL));
const auto isnan_v = (fpc_v == FP_NAN);

if (iszero_u || (isnan_v || isinf_v))
{
return operator=(v);
if (iszero_u)
{
data.first = float_type { 0.0F };
data.second = float_type { 0.0F };
}

const auto iszero_v = ((fpc_v == FP_ZERO) || (fpc_v == FP_SUBNORMAL));

return ((!iszero_v) ? operator=(v) : *this);
}

if (this == &v)
Expand Down Expand Up @@ -482,12 +490,20 @@ class cpp_double_fp_backend
return *this;
}

const auto iszero_u = (fpc_u == FP_ZERO);
const auto iszero_u = ((fpc_u == FP_ZERO) || (fpc_u == FP_SUBNORMAL));
const auto isnan_v = (fpc_v == FP_NAN);

if (iszero_u || (isnan_v || isinf_v))
{
return operator=(-v);
if (iszero_u)
{
data.first = float_type { 0.0F };
data.second = float_type { 0.0F };
}

const auto iszero_v = ((fpc_v == FP_ZERO) || (fpc_v == FP_SUBNORMAL));

return ((!iszero_v) ? operator=(-v) : *this);
}

if (this == &v)
Expand Down
2 changes: 1 addition & 1 deletion test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ alias precision_tests : test_preserve_source_precision_gmp test_preserve_source_
rule get_function_tests
{
local result ;
for local source in test_log.cpp test_pow.cpp test_pow_df.cpp test_sinh.cpp test_sqrt.cpp test_cosh.cpp test_tanh.cpp test_sin.cpp test_cos.cpp test_tan.cpp test_asin.cpp test_acos.cpp test_atan.cpp test_round.cpp test_fpclassify.cpp test_sf_import_c99.cpp
for local source in test_exp.cpp test_log.cpp test_pow.cpp test_sinh.cpp test_sqrt.cpp test_cosh.cpp test_tanh.cpp test_sin.cpp test_cos.cpp test_tan.cpp test_asin.cpp test_acos.cpp test_atan.cpp test_round.cpp test_fpclassify.cpp test_sf_import_c99.cpp
{
result += [ run $(source) gmp no_eh_support
: # command line
Expand Down
13 changes: 12 additions & 1 deletion test/test_exp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
#include <boost/multiprecision/cpp_bin_float.hpp>
#endif
#ifdef TEST_CPP_DOUBLE_FLOAT
#if defined(BOOST_MATH_USE_FLOAT128)
#include <boost/multiprecision/float128.hpp>
#endif
#include <boost/multiprecision/cpp_double_fp.hpp>
#endif

Expand Down Expand Up @@ -206,8 +209,16 @@ void test()
BOOST_CHECK_LE(exp(bug_case), (std::numeric_limits<T>::min)());
}
}

bug_case = log((std::numeric_limits<T>::max)()) / -1.0005;
for (unsigned i = 0; i < 20; ++i, bug_case /= 1.05)
unsigned i { 0U };

#if defined(TEST_CPP_DOUBLE_FLOAT)
BOOST_IF_CONSTEXPR(std::is_same<T, boost::multiprecision::cpp_double_float>::value) { for ( ; i < 7; ++i, bug_case /= 1.05) { ; } }
BOOST_IF_CONSTEXPR(std::is_same<T, boost::multiprecision::cpp_double_double>::value) { for ( ; i < 3; ++i, bug_case /= 1.05) { ; } }
BOOST_IF_CONSTEXPR(std::is_same<T, boost::multiprecision::cpp_double_long_double>::value) { for ( ; i < 3; ++i, bug_case /= 1.05) { ; } }
#endif
for ( ; i < 20U; ++i, bug_case /= static_cast<T>(1.05L))
{
BOOST_CHECK_GE(exp(bug_case), (std::numeric_limits<T>::min)());
}
Expand Down

0 comments on commit c348685

Please sign in to comment.