Skip to content

Commit

Permalink
Try remove unused lines and more cover
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed Jan 15, 2025
1 parent 8dc96ef commit a8efc3a
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 83 deletions.
96 changes: 19 additions & 77 deletions include/boost/multiprecision/cpp_double_fp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1987,48 +1987,28 @@ constexpr void eval_convert_to(unsigned long long* result, const cpp_double_fp_b
}
else
{
BOOST_IF_CONSTEXPR(std::numeric_limits<unsigned long long>::digits >= cpp_df_qf_detail::ccmath::numeric_limits<FloatingPointType>::digits)
{
*result = static_cast<unsigned long long>(backend.crep().first);
*result += static_cast<unsigned long long>(backend.crep().second);
}
else
{
cpp_double_fp_backend<FloatingPointType> source = backend;

*result = 0;

for(auto digit_count = 0;
digit_count < cpp_double_fp_backend<FloatingPointType>::my_digits;
digit_count += std::numeric_limits<unsigned long long>::digits)
{
const auto next = static_cast<unsigned long long>(source.crep().first);

*result += next;

eval_subtract(source, cpp_double_fp_backend<FloatingPointType>(next));
}
}
*result = static_cast<unsigned long long>(backend.crep().first);
*result += static_cast<unsigned long long>(backend.crep().second);
}
}

#ifdef BOOST_HAS_INT128
template <typename FloatingPointType>
constexpr void eval_convert_to(int128_type* result, const cpp_double_fp_backend<FloatingPointType>& backend)
constexpr void eval_convert_to(boost::int128_type* result, const cpp_double_fp_backend<FloatingPointType>& backend)
{
const auto fpc = eval_fpclassify(backend);

if (fpc != FP_NORMAL)
{
*result = static_cast<int128_type>(backend.crep().first);
*result = static_cast<boost::int128_type>(backend.crep().first);

return;
}

constexpr int128_type my_max_val = (((static_cast<int128_type>(1) << (sizeof(int128_type) * CHAR_BIT - 2)) - 1) << 1) + 1;
constexpr int128_type my_min_val = static_cast<int128_type>(-my_max_val - 1);
constexpr boost::int128_type my_max_val = (((static_cast<boost::int128_type>(1) << (sizeof(boost::int128_type) * CHAR_BIT - 2)) - 1) << 1) + 1;
constexpr boost::int128_type my_min_val = static_cast<boost::int128_type>(-my_max_val - 1);

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

constexpr c_type my_max { static_cast<c_type>(my_max_val) };
constexpr c_type my_min { static_cast<c_type>(my_min_val) };
Expand All @@ -2045,51 +2025,31 @@ constexpr void eval_convert_to(int128_type* result, const cpp_double_fp_backend<
}
else
{
BOOST_IF_CONSTEXPR(static_cast<int>(static_cast<int>(sizeof(int128_type)) * CHAR_BIT) >= cpp_df_qf_detail::ccmath::numeric_limits<FloatingPointType>::digits)
{
*result = static_cast<int128_type>(backend.crep().first);
*result += static_cast<int128_type>(backend.crep().second);
}
else
{
cpp_double_fp_backend<FloatingPointType> source = backend;

*result = 0;

for(auto digit_count = static_cast<int>(0);
digit_count < cpp_double_fp_backend<FloatingPointType>::my_digits;
digit_count += static_cast<int>(static_cast<int>(sizeof(int128_type)) * CHAR_BIT))
{
const auto next = static_cast<int128_type>(source.crep().first);

*result += next;

eval_subtract(source, cpp_double_fp_backend<FloatingPointType>(next));
}
}
*result = static_cast<boost::int128_type>(backend.crep().first);
*result += static_cast<boost::int128_type>(backend.crep().second);
}
}

template <typename FloatingPointType>
constexpr void eval_convert_to(uint128_type* result, const cpp_double_fp_backend<FloatingPointType>& backend)
constexpr void eval_convert_to(boost::uint128_type* result, const cpp_double_fp_backend<FloatingPointType>& backend)
{
const auto fpc = eval_fpclassify(backend);

if (fpc != FP_NORMAL)
{
*result = static_cast<uint128_type>(backend.crep().first);
*result = static_cast<boost::uint128_type>(backend.crep().first);

return;
}

constexpr uint128_type my_max_val
constexpr boost::uint128_type my_max_val
{
(std::is_same<FloatingPointType, float>::value && (cpp_df_qf_detail::ccmath::numeric_limits<float>::digits == 24))
? static_cast<uint128_type>(FLT_MAX)
: static_cast<uint128_type>(~static_cast<uint128_type>(0))
? static_cast<boost::uint128_type>(FLT_MAX)
: static_cast<boost::uint128_type>(~static_cast<boost::uint128_type>(0))
};

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

constexpr c_type my_max { static_cast<c_type>(my_max_val) };

Expand All @@ -2101,28 +2061,10 @@ constexpr void eval_convert_to(uint128_type* result, const cpp_double_fp_backend
}
else
{
BOOST_IF_CONSTEXPR(static_cast<int>(static_cast<int>(sizeof(uint128_type)) * CHAR_BIT) >= cpp_df_qf_detail::ccmath::numeric_limits<FloatingPointType>::digits)
{
*result = static_cast<int128_type>(backend.crep().first);
*result += static_cast<int128_type>(backend.crep().second);
}
else
{
cpp_double_fp_backend<FloatingPointType> source = backend;

*result = 0;

for(auto digit_count = static_cast<int>(0);
digit_count < cpp_double_fp_backend<FloatingPointType>::my_digits;
digit_count += static_cast<int>(static_cast<int>(sizeof(uint128_type)) * CHAR_BIT))
{
const auto next = static_cast<uint128_type>(source.crep().first);

*result += next;
*result = static_cast<boost::int128_type>(backend.crep().first);
*result += static_cast<boost::int128_type>(backend.crep().second);

eval_subtract(source, cpp_double_fp_backend<FloatingPointType>(next));
}
}
*result = static_cast<boost::uint128_type>(*result);
}
}
#endif
Expand All @@ -2133,7 +2075,7 @@ constexpr typename ::std::enable_if<cpp_df_qf_detail::is_floating_point<OtherFlo
{
const auto fpc = eval_fpclassify(backend);

// TBD: Implement min/max chek for the destination floating-point type result.
// TBD: Implement min/max check for the destination floating-point type result.

if (fpc != FP_NORMAL)
{
Expand Down
75 changes: 69 additions & 6 deletions test/test_various_edges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,27 @@ namespace local
}
}

{
float_type flt_val { (std::numeric_limits<float_type>::max)() };
ctrl_type ctl_val { flt_val };

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

float_type flt_factor { 1234.56e-12F * dis(gen) };

flt_val = flt_factor * flt_val;
ctl_val *= ctrl_type { flt_factor };

const bool result_mul_is_ok { local::is_close_fraction(flt_val, float_type { ctl_val }, std::numeric_limits<float_type>::epsilon() * 32) };

BOOST_TEST(result_mul_is_ok);

result_is_ok = (result_mul_is_ok && result_is_ok);
}
}

{
float_type flt_val { };
ctrl_type ctl_val { };
Expand Down Expand Up @@ -222,9 +243,9 @@ namespace local
const float_type inf_neg_02 { "-1e100002" };
const float_type inf_neg_03 { "-1e100003" };

const float_type zero_01 { "1e-100001" };
const float_type zero_02 { "1e-100002" };
const float_type zero_03 { "1e-100003" };
const float_type tiny_01 { "1e-100001" };
const float_type tiny_02 { "1e-100002" };
const float_type tiny_03 { "1e-100003" };

BOOST_TEST(result_is_ok = (isinf(inf_pos_01) && result_is_ok));
BOOST_TEST(result_is_ok = (isinf(inf_pos_02) && result_is_ok));
Expand All @@ -234,9 +255,9 @@ namespace local
BOOST_TEST(result_is_ok = (isinf(inf_neg_02) && signbit(inf_neg_02) && result_is_ok));
BOOST_TEST(result_is_ok = (isinf(inf_neg_03) && signbit(inf_neg_03) && result_is_ok));

BOOST_TEST(result_is_ok = ((fpclassify(zero_01) == FP_ZERO) && result_is_ok));
BOOST_TEST(result_is_ok = ((fpclassify(zero_02) == FP_ZERO) && result_is_ok));
BOOST_TEST(result_is_ok = ((fpclassify(zero_03) == FP_ZERO) && result_is_ok));
BOOST_TEST(result_is_ok = ((fpclassify(tiny_01) == FP_ZERO) && result_is_ok));
BOOST_TEST(result_is_ok = ((fpclassify(tiny_02) == FP_ZERO) && result_is_ok));
BOOST_TEST(result_is_ok = ((fpclassify(tiny_03) == FP_ZERO) && result_is_ok));
}

for(auto i = static_cast<unsigned>(UINT8_C(0)); i < static_cast<unsigned>(UINT8_C(8)); ++i)
Expand All @@ -261,6 +282,21 @@ namespace local
BOOST_TEST(result_is_ok = ((fpclassify(sub_result_zero) == FP_ZERO) && result_is_ok));
}

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

float_type flt_numpos { ::my_one<float_type>() * dis(gen) };
float_type flt_numneg { ::my_one<float_type>() * -dis(gen) };
float_type flt_denom { ::my_zero<float_type>() * dis(gen) };

const float_type div_result_zero_pos { flt_numpos / flt_denom };
const float_type div_result_zero_neg { flt_numneg / flt_denom };

BOOST_TEST(result_is_ok = ((fpclassify(div_result_zero_pos) == FP_INFINITE) && result_is_ok));
BOOST_TEST(result_is_ok = ((fpclassify(div_result_zero_neg) == FP_INFINITE) && signbit(div_result_zero_neg) && result_is_ok));
}

for(auto i = static_cast<unsigned>(UINT8_C(0)); i < static_cast<unsigned>(UINT8_C(8)); ++i)
{
static_cast<void>(i);
Expand Down Expand Up @@ -560,6 +596,33 @@ namespace local
result_is_ok = (result_exp_small_is_ok && 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 arg_small_scale { float_type {::my_one<float_type>() / 24 } * static_cast<float_type>(dist(gen)) };

const float_type result_exp_small_scale { exp(arg_small_scale) };

using ctrl_type = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<100>, boost::multiprecision::et_off>;

const ctrl_type result_ctrl { exp(ctrl_type { arg_small_scale }) };

bool result_exp_small_scale_is_ok
{
local::is_close_fraction
(
result_exp_small_scale,
float_type { result_ctrl },
std::numeric_limits<float_type>::epsilon() * 512
)
};

BOOST_TEST(result_exp_small_scale_is_ok);

result_is_ok = (result_exp_small_scale_is_ok && result_is_ok);
}

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

0 comments on commit a8efc3a

Please sign in to comment.