Skip to content

Reduce tols in sin/cos/tan tests - #1479

Merged
ckormanyos merged 3 commits into
developfrom
better_sincostan_testing
Oct 1, 2026
Merged

ckormanyos merged 3 commits into
developfrom
better_sincostan_testing

Conversation

@ckormanyos

Copy link
Copy Markdown
Member

This PR reduces the tolerances in sin(), cos(), tan() testing based on improvements in #1475

@codecov

codecov Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.7%. Comparing base (bf02597) to head (e769094).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #1479     +/-   ##
=========================================
- Coverage     98.7%   98.7%   -0.0%     
=========================================
  Files          315     315             
  Lines        26457   26449      -8     
  Branches      2253    2253             
=========================================
- Hits         26112   26104      -8     
  Misses         345     345             
Files with missing lines Coverage Δ
test/test_sin_cos.cpp 100.0% <100.0%> (ø)
test/test_tan.cpp 100.0% <100.0%> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bf02597...e769094. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread test/test_sin_cos.cpp
Comment thread test/test_tan.cpp
@@ -75,7 +56,7 @@
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.

Comment thread test/test_tan.cpp
// https://www.boost.org/LICENSE_1_0.txt

#include "testing_config.hpp"
#include <chrono>

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.

Since time_point removed, no other usages in <chrono> now

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done by @ibmibmibm

@ckormanyos

Copy link
Copy Markdown
Member Author

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

I try (whenever refactoring a function or its tests) to use fixed seeds. I have grown to agree strongly with the fixed seed approach. Unfortunately, I missed the one mentioned here and it should be changed.

Hi @ibmibmibm when we refactor functions and tests, repülace time_point with fixed seeds. And delete the time_point facility when reworking. I have recently commited a few examples doing this stability measure.

@ckormanyos

Copy link
Copy Markdown
Member Author

Could we change the same eps in test_cos()? it's at line 110.

Yes please, just do it for us at your convenience.

Cc: @mborland

@ckormanyos

Copy link
Copy Markdown
Member Author

You can mix the cosine tolerance reduction with generally any and all refactoring of the trigonometric elementary functions sine, cosine, tangent, arcsine, arccosine and arctangent.

Finish it.

ibmibmibm added a commit to ibmibmibm/decimal that referenced this pull request Oct 1, 2026
The random cos test now uses 16 float eps, the same as the sin test
in boostorg#1479. Over 200000 random points the largest cos error is 5 eps.

The asin edge test now seeds its generator with a fixed value
instead of the clock, so a failure is reproducible.
@ckormanyos
ckormanyos merged commit c4e5174 into develop Oct 1, 2026
75 checks passed
@ckormanyos
ckormanyos deleted the better_sincostan_testing branch October 1, 2026 14:15
ibmibmibm added a commit to ibmibmibm/decimal that referenced this pull request Oct 1, 2026
The random cos test now uses 16 float eps, the same as the sin test
in boostorg#1479. Over 200000 random points the largest cos error is 5 eps.

The asin edge test now seeds its generator with a fixed value
instead of the clock, so a failure is reproducible.
mborland pushed a commit that referenced this pull request Oct 2, 2026
This PR follows the review of #1479.

`test_cos()` in `test/test_sin_cos.cpp` now uses a tolerance of 16 float
eps, the same value that #1479 uses for `test_sin()`. The old value was
35 eps. Over 200000 random points in [-2π, 2π], the largest cos error
for all decimal types is 5 eps.

`test_asin_edge()` in `test/test_asin.cpp` now seeds its generator with
a fixed value. The old code seeded it from the clock, so a failure was
not reproducible. This change also removes the unused `time_point()`
helper, `std::random_device`, and `<chrono>`.

This PR does not change `test/test_tan.cpp` because #1479 already
changes the seed there.

Both tests pass with GCC and Clang.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants