Repository navigation
keep the sign of cos(y) in sinh near the overflow boundary - #361
Open
HuzaifaChaudary wants to merge 1 commit into
Open
HuzaifaChaudary wants to merge 1 commit into
HuzaifaChaudary wants to merge 1 commit into
Conversation
the large |x| path of sinh built its real part as RealType(signOf: z.x, magnitudeOf: cos(y)) , which drops the sign of cos(y) . so sinh(x + iy) had the wrong real part whenever cos(y) < 0 , and sin(z) , which goes through sinh , had the wrong imaginary part for large |im z| . it now multiplies cos(y) by the sign of x , like cosh does with sin(y) .
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.
#352 moved the sign of x into the phase on the large |x| path of
sinh, but it does it withRealType(signOf: z.x, magnitudeOf: RealType.cos(z.y)), which also throws away the sign ofcos(y). so whenevercos(y)is negative the real part has the wrong sign , andsin, which goes throughsinh, gets the wrong imaginary part for a large imaginary input :the fixed values match mpmath . the fix multiplies
cos(y)by the sign of x , the same waycoshalready does withsin(y).the tests from #352 only use y = ±π/4 , where
cos(y)is positive . this adds the same near overflow checks at y = ±3π/4 forsinh, and two forcoshso both functions cover that quadrant . the four newsinhreal part checks fail on main forFloatandDouble, and the whole suite passes with the change .i found it by comparing the complex elementary functions against mpmath on random inputs over a wide range of magnitudes . after this change everything else was within 5 ulp normwise , apart from a few tiny
atan/atanhinputs where mpmath itself ran out of precision .