Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions test/test_sin_cos.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2024 Matt Borland
// Copyright 2024 Christopher Kormanyos
// Copyright 2024 - 2026 Christopher Kormanyos
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

Expand Down Expand Up @@ -59,7 +59,7 @@ auto test_sin() -> void
auto ret_val {std::sin(val1)};
auto ret_dec {static_cast<float>(sin(d1))};

if (!BOOST_TEST(std::fabs(ret_val - ret_dec) < 40*std::numeric_limits<float>::epsilon()))
if (!BOOST_TEST(std::fabs(ret_val - ret_dec) < 16*std::numeric_limits<float>::epsilon()))
Comment thread
ckormanyos marked this conversation as resolved.
{
// LCOV_EXCL_START
std::cerr << "Val 1: " << val1
Expand Down Expand Up @@ -270,9 +270,7 @@ namespace local
from_chars(ctrl_strings[i], ctrl_strings[i] + std::strlen(ctrl_strings[i]), ctrl_values[i])
);

const decimal_type local_tol = ((ctrl_values[i] < decimal_type { 1, -1 }) ? my_tol * 16 : my_tol);

const auto result_sin_is_ok = is_close_fraction(sin_values[i], ctrl_values[i], local_tol);
const auto result_sin_is_ok = is_close_fraction(sin_values[i], ctrl_values[i], my_tol);

result_is_ok = (result_sin_is_ok && result_is_ok);
}
Expand Down Expand Up @@ -360,9 +358,7 @@ namespace local
from_chars(ctrl_strings[i], ctrl_strings[i] + std::strlen(ctrl_strings[i]), ctrl_values[i])
);

const decimal_type local_tol = ((ctrl_values[i] < decimal_type { 1, -1 }) ? my_tol * 16 : my_tol);

const auto result_cos_is_ok = is_close_fraction(cos_values[i], ctrl_values[i], local_tol);
const auto result_cos_is_ok = is_close_fraction(cos_values[i], ctrl_values[i], my_tol);

result_is_ok = (result_cos_is_ok && result_is_ok);
}
Expand Down Expand Up @@ -498,24 +494,24 @@ auto main() -> int
test_cos<decimal_fast64_t>();

{
const auto result_sin128_is_ok = local::test_sin_128<decimal128_t>(0x800);
const auto result_cos128_is_ok = local::test_cos_128<decimal128_t>(0x800);
const auto result_sin128_is_ok = local::test_sin_128<decimal128_t>(16);
const auto result_cos128_is_ok = local::test_cos_128<decimal128_t>(16);

BOOST_TEST(result_sin128_is_ok);
BOOST_TEST(result_cos128_is_ok);
}

{
const auto result_sin128_is_ok = local::test_sin_128<decimal_fast128_t>(0x800);
const auto result_cos128_is_ok = local::test_cos_128<decimal_fast128_t>(0x800);
const auto result_sin128_is_ok = local::test_sin_128<decimal_fast128_t>(16);
const auto result_cos128_is_ok = local::test_cos_128<decimal_fast128_t>(16);

BOOST_TEST(result_sin128_is_ok);
BOOST_TEST(result_cos128_is_ok);
}

{
const auto result_sin064_tiny_is_ok = local::test_sin_tiny<decimal64_t>(0x400);
const auto result_sin128_tiny_is_ok = local::test_sin_tiny<decimal128_t>(0x400);
const auto result_sin064_tiny_is_ok = local::test_sin_tiny<decimal64_t>(16);
const auto result_sin128_tiny_is_ok = local::test_sin_tiny<decimal128_t>(16);

BOOST_TEST(result_sin064_tiny_is_ok);
BOOST_TEST(result_sin128_tiny_is_ok);
Expand Down
29 changes: 5 additions & 24 deletions test/test_tan.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 Matt Borland
// Copyright 2023 Christopher Kormanyos
// Copyright 2023 - 2026 Christopher Kormanyos
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

Expand All @@ -26,25 +26,6 @@ auto my_zero() -> boost::decimal::decimal32_t&;

namespace local
{
template<typename IntegralTimePointType,
typename ClockType = std::chrono::high_resolution_clock>
auto time_point() noexcept -> IntegralTimePointType
{
using local_integral_time_point_type = IntegralTimePointType;
using local_clock_type = ClockType;

const auto current_now =
static_cast<std::uintmax_t>
(
std::chrono::duration_cast<std::chrono::nanoseconds>
(
local_clock_type::now().time_since_epoch()
).count()
);

return static_cast<local_integral_time_point_type>(current_now);
}

template<typename NumericType>
auto is_close_fraction(const NumericType& a,
const NumericType& b,
Expand Down Expand Up @@ -75,7 +56,7 @@ namespace local
std::random_device rd;
std::mt19937_64 gen(rd());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rd() is not used if we reset the seed after the constructor

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like it if we used a fixed seed here in the testing so we don't get mystery failures or spurious coverage changes.


gen.seed(time_point<typename std::mt19937_64::result_type>());
gen.seed(static_cast<typename std::mt19937_64::result_type>(42));

auto dis =
std::uniform_real_distribution<float>
Expand Down Expand Up @@ -242,9 +223,9 @@ auto main() -> int
{
auto result_is_ok = true;

const auto result_pos_is_ok = local::test_tan(256, false, 0.03125L, 1.48L);
const auto result_neg_is_ok = local::test_tan(256, true, 0.03125L, 1.48L);
const auto result_pos_near_pi_half_is_ok = local::test_tan(4096, false, 1.48L, 1.56L);
const auto result_pos_is_ok = local::test_tan(96, false, 0.03125L, 1.48L); // High tolerance due to float conversion for comparison.
const auto result_neg_is_ok = local::test_tan(96, true, 0.03125L, 1.48L); // High tolerance due to float conversion for comparison.
const auto result_pos_near_pi_half_is_ok = local::test_tan(512, false, 1.48L, 1.56L); // High tolerance due to float conversion for comparison.

const auto result_phase_is_ok = local::test_tan_phase();

Expand Down
Loading