Skip to content

Commit c348685

Browse files
committed
Restore test_exp also subnormals in add/sub
1 parent b42d427 commit c348685

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

include/boost/multiprecision/cpp_double_fp.hpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,20 @@ class cpp_double_fp_backend
432432
return *this;
433433
}
434434

435-
const auto iszero_u = (fpc_u == FP_ZERO);
435+
const auto iszero_u = ((fpc_u == FP_ZERO) || (fpc_u == FP_SUBNORMAL));
436436
const auto isnan_v = (fpc_v == FP_NAN);
437437

438438
if (iszero_u || (isnan_v || isinf_v))
439439
{
440-
return operator=(v);
440+
if (iszero_u)
441+
{
442+
data.first = float_type { 0.0F };
443+
data.second = float_type { 0.0F };
444+
}
445+
446+
const auto iszero_v = ((fpc_v == FP_ZERO) || (fpc_v == FP_SUBNORMAL));
447+
448+
return ((!iszero_v) ? operator=(v) : *this);
441449
}
442450

443451
if (this == &v)
@@ -482,12 +490,20 @@ class cpp_double_fp_backend
482490
return *this;
483491
}
484492

485-
const auto iszero_u = (fpc_u == FP_ZERO);
493+
const auto iszero_u = ((fpc_u == FP_ZERO) || (fpc_u == FP_SUBNORMAL));
486494
const auto isnan_v = (fpc_v == FP_NAN);
487495

488496
if (iszero_u || (isnan_v || isinf_v))
489497
{
490-
return operator=(-v);
498+
if (iszero_u)
499+
{
500+
data.first = float_type { 0.0F };
501+
data.second = float_type { 0.0F };
502+
}
503+
504+
const auto iszero_v = ((fpc_v == FP_ZERO) || (fpc_v == FP_SUBNORMAL));
505+
506+
return ((!iszero_v) ? operator=(-v) : *this);
491507
}
492508

493509
if (this == &v)

test/Jamfile.v2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ alias precision_tests : test_preserve_source_precision_gmp test_preserve_source_
262262
rule get_function_tests
263263
{
264264
local result ;
265-
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
265+
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
266266
{
267267
result += [ run $(source) gmp no_eh_support
268268
: # command line

test/test_exp.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
#include <boost/multiprecision/cpp_bin_float.hpp>
6060
#endif
6161
#ifdef TEST_CPP_DOUBLE_FLOAT
62+
#if defined(BOOST_MATH_USE_FLOAT128)
63+
#include <boost/multiprecision/float128.hpp>
64+
#endif
6265
#include <boost/multiprecision/cpp_double_fp.hpp>
6366
#endif
6467

@@ -206,8 +209,16 @@ void test()
206209
BOOST_CHECK_LE(exp(bug_case), (std::numeric_limits<T>::min)());
207210
}
208211
}
212+
209213
bug_case = log((std::numeric_limits<T>::max)()) / -1.0005;
210-
for (unsigned i = 0; i < 20; ++i, bug_case /= 1.05)
214+
unsigned i { 0U };
215+
216+
#if defined(TEST_CPP_DOUBLE_FLOAT)
217+
BOOST_IF_CONSTEXPR(std::is_same<T, boost::multiprecision::cpp_double_float>::value) { for ( ; i < 7; ++i, bug_case /= 1.05) { ; } }
218+
BOOST_IF_CONSTEXPR(std::is_same<T, boost::multiprecision::cpp_double_double>::value) { for ( ; i < 3; ++i, bug_case /= 1.05) { ; } }
219+
BOOST_IF_CONSTEXPR(std::is_same<T, boost::multiprecision::cpp_double_long_double>::value) { for ( ; i < 3; ++i, bug_case /= 1.05) { ; } }
220+
#endif
221+
for ( ; i < 20U; ++i, bug_case /= static_cast<T>(1.05L))
211222
{
212223
BOOST_CHECK_GE(exp(bug_case), (std::numeric_limits<T>::min)());
213224
}

0 commit comments

Comments
 (0)