Skip to content

Commit

Permalink
More tests and minor corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed Jan 14, 2025
1 parent cac5725 commit 382cd8f
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 18 deletions.
19 changes: 12 additions & 7 deletions include/boost/multiprecision/cpp_double_fp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2030,14 +2030,18 @@ constexpr void eval_convert_to(int128_type* result, const cpp_double_fp_backend<

using c_type = typename std::common_type<int128_type, FloatingPointType>::type;

constexpr c_type my_max = static_cast<c_type>(my_max_val);
const c_type ct = cpp_df_qf_detail::ccmath::fabs(backend.crep().first);
constexpr c_type my_max { static_cast<c_type>(my_max_val) };
constexpr c_type my_min { static_cast<c_type>(my_min_val) };

const c_type ct { static_cast<c_type>(backend.crep().first) };

if (ct > my_max)
{
*result = backend.crep().first >= typename cpp_double_fp_backend<FloatingPointType>::float_type(0U)
? my_max_val
: my_min_val;
*result = my_max_val;
}
if (ct < my_min)
{
*result = my_min_val;
}
else
{
Expand Down Expand Up @@ -2091,8 +2095,9 @@ constexpr void eval_convert_to(uint128_type* result, const cpp_double_fp_backend

using c_type = typename std::common_type<uint128_type, FloatingPointType>::type;

const c_type my_max = static_cast<c_type>(my_max_val);
const c_type ct = cpp_df_qf_detail::ccmath::fabs(backend.crep().first);
constexpr c_type my_max { static_cast<c_type>(my_max_val) };

const c_type ct { static_cast<c_type>(backend.crep().first) };

if (ct > my_max)
{
Expand Down
89 changes: 78 additions & 11 deletions test/test_various_edges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ namespace local
using float_type = FloatType;
using ctrl_type = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<100>, boost::multiprecision::et_off>;

std::mt19937_64 gen;

gen.seed(time_point<typename std::mt19937_64::result_type>());
std::mt19937_64 gen { time_point<typename std::mt19937_64::result_type>() };

auto dis =
std::uniform_real_distribution<float>
Expand Down Expand Up @@ -285,6 +283,77 @@ namespace local
BOOST_TEST(result_is_ok = ((conversion_result_min == (std::numeric_limits<signed long long>::min)()) && result_is_ok));
}

{
for(auto i = static_cast<unsigned>(UINT8_C(0)); i < static_cast<unsigned>(UINT8_C(16)); ++i)
{
static_cast<void>(i);

const float_type flt_factor_inf_pos { std::numeric_limits<float_type>::infinity() * dis(gen) };
const float_type flt_factor_inf_neg { std::numeric_limits<float_type>::infinity() * -dis(gen) };

{
const float_type val_inf_pos_neg_add { flt_factor_inf_pos + flt_factor_inf_neg };

const bool result_inf_pos_neg_add_is_ok { isnan(val_inf_pos_neg_add) };

BOOST_TEST(result_inf_pos_neg_add_is_ok);

result_is_ok = (result_inf_pos_neg_add_is_ok && result_is_ok);
}

{
const float_type val_inf_pos_pos_add { flt_factor_inf_pos + -flt_factor_inf_neg };

const bool result_inf_pos_pos_add_is_ok { isinf(val_inf_pos_pos_add) };

BOOST_TEST(result_inf_pos_pos_add_is_ok);

result_is_ok = (result_inf_pos_pos_add_is_ok && result_is_ok);
}

{
const float_type val_inf_neg_neg_add { -flt_factor_inf_pos + (flt_factor_inf_neg) };

const bool result_inf_neg_neg_add_is_ok { isinf(val_inf_neg_neg_add) && signbit(val_inf_neg_neg_add) };

BOOST_TEST(result_inf_neg_neg_add_is_ok);

result_is_ok = (result_inf_neg_neg_add_is_ok && result_is_ok);
}

{
const float_type val_inf_pos_neg_sub { flt_factor_inf_pos - flt_factor_inf_neg };

const bool result_inf_pos_neg_sub_is_ok { isinf(val_inf_pos_neg_sub) };

BOOST_TEST(result_inf_pos_neg_sub_is_ok);

result_is_ok = (result_inf_pos_neg_sub_is_ok && result_is_ok);
}

{
const float_type val_inf_pos_pos_sub { flt_factor_inf_pos - (-flt_factor_inf_neg) };

const bool result_inf_pos_pos_sub_is_ok { isnan(val_inf_pos_pos_sub) };

BOOST_TEST(result_inf_pos_pos_sub_is_ok);

result_is_ok = (result_inf_pos_pos_sub_is_ok && result_is_ok);
}

{
const float_type val_inf_neg_neg_sub { -flt_factor_inf_pos - (flt_factor_inf_neg) };

const bool result_inf_neg_neg_sub_is_ok { isnan(val_inf_neg_neg_sub) };

BOOST_TEST(result_inf_neg_neg_sub_is_ok);

result_is_ok = (result_inf_neg_neg_sub_is_ok && result_is_ok);
}

}
}

return result_is_ok;
}

Expand All @@ -293,9 +362,7 @@ namespace local
{
using float_type = FloatType;

std::mt19937_64 gen;

gen.seed(time_point<typename std::mt19937_64::result_type>());
std::mt19937_64 gen { time_point<typename std::mt19937_64::result_type>() };

auto dis =
std::uniform_real_distribution<float>
Expand Down Expand Up @@ -325,9 +392,7 @@ namespace local
{
using float_type = FloatType;

std::mt19937_64 gen;

gen.seed(time_point<typename std::mt19937_64::result_type>());
std::mt19937_64 gen { time_point<typename std::mt19937_64::result_type>() };

std::uniform_real_distribution<float>
dist
Expand Down Expand Up @@ -723,11 +788,13 @@ namespace local
{
static_cast<void>(index);

float_type arg_one_minus =
float_type arg_one_minus
{
static_cast<float_type>
(
-static_cast<int>(::my_one<float_type>() * static_cast<float_type>(dist(gen)))
);
)
};

const auto log_one_minus = log(arg_one_minus);

Expand Down

0 comments on commit 382cd8f

Please sign in to comment.