Repository navigation
Conversation
…sin` and `hacoversin` `1 - sin(x)` cancels where `sin(x)` is close to one, by up to about 2^40 ULPs within 1e-8 of `π/2 + 2πk`. Where `sin(x) > 0`, evaluate it as `cos(x)^2 / (1 + sin(x))` instead: `cos(x)` keeps its relative accuracy near its zeros, and the denominator does not cancel. The fixtures came from Julia's Float64 `1 .- sin.(x)`, the same expression; they are now evaluated in BigFloat, with a new set close to where `sin(x)` is one or minus one. `coversin( π/2 )` now returns `1.87e-33`, the exact value for the double nearest `π/2`, so the examples say `~0.0`. Signed-off-by: Abhist17 <abhistkamle.170903@gmail.com>
Signed-off-by: Abhist17 <abhistkamle.170903@gmail.com>
6 of 7 tasks
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/coversinandmath/base/special/hacoversinascos(x)^2 / (1 + sin(x))(halved forhacoversin) wheresin(x) > 0(JS and C), instead of1 - sin(x).1 - sin(x)cancels whereversin(x)is close to one:1 - sin(x) = (1 - sin(x))(1 + sin(x)) / (1 + sin(x)) = cos(x)^2 / (1 + sin(x)). Near the cancellation,cos(x)is near a zero, whichcoscomputes with full relative accuracy after its own argument reduction, and the denominator is near 2. Wheresin(x) <= 0,1 - sin(x)doesn't cancel and is unchanged.BigFloat. They came from Julia'sFloat641 .- sin.(x)(the expression being replaced) and were checked at 0 ULPs, so they pinned the cancellation. Against the exact values,developis off by up to about 2^22 ULPs onmedium_positive.json. This PR passes every set at 2 to 3 ULPs, and those are the new tolerances.near_extrema.json, 4200 values within10^-8to10^-1of±π/2 + 2πkfork = -10..10.developis off by up to about 2^40 ULPs there; this PR passes at 2.coversin( 3.141592653589793/2.0 )examples from0.0to~0.0. The double nearestπ/2is notπ/2, and1 - sinof it is1.87e-33, which the doctest now sees.Related Issues
None. The same change for
covercosandhacovercos, where1 + sin(x)cancels nearsin(x) = -1, follows separately.Questions
No.
Other
test.jsandtest.native.jspass.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?