Repository navigation
Conversation
…sm1` Outside `[-π/4,π/4]`, `cosm1` returned `cos(x) - 1`, which cancels where `cos(x)` is close to one; near `x = 2πk` the result could be off by about 2^30 ULPs. Use `-2 sin^2(x/2)` there instead, the same half-angle identity as stdlib-js#15609 uses for `versin`. The test for that range compared against `cos(x) - 1` itself; it now uses fixtures evaluated in BigFloat, including values close to multiples of 2π. Signed-off-by: Abhist17 <abhistkamle.170903@gmail.com>
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
Abhist17
marked this pull request as draft
October 14, 2026 04:17
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request:
math/base/special/cosm1as-2 sin^2(x/2)outside[-π/4,π/4](JS and C), instead ofcos(x) - 1.cos(x) - 1cancels wherevercos(x)is close to one, which is near every multiple of 2π, not only near zero (inside[-π/4,π/4]the polynomial already handles that):x/2is exact andsinhas its own argument reduction, so the half-angle form has no cancellation. #15609 uses the same identity forversin(versin(x) = -cosm1(x)).|x| > π/4, which comparedcosm1(x)againstcos(x) - 1(the expression being replaced) at 1 ULP, with fixtures evaluated in 256-bitBigFloatby a new Julia runner. The fixtures cover the same two ranges,[π/4, 4π]and[-4π, -π/4], plus 2000 values within10^-8to10^-1of±2πkfork = 1..10.developis off by up to about 2^30 ULPs on those, and this PR passes all three at 2.Related Issues
None.
Questions
No.
Other
test.jsandtest.native.jspass.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?