Repository navigation
Fix the sine in the small-cosine branch of CROTG/ZROTG - #6282
Merged
martin-frbg merged 1 commit intoNov 27, 2026
Merged
Conversation
When |a|^2 < (|a|^2 + |b|^2) * safmin, the unscaled branch computed the sine from the real part of a only, so for a complex a the sine had the wrong phase and |c|^2 + |s|^2 != 1. Use the full product conj(b) * a / sqrt(|a|^2 * h), as the neighbouring branch does.
Collaborator
|
Thanks - not sure what happened to CI, I'll close and reopen to initiate a (hopefully) full rerun |
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.
In the unscaled path of
interface/zrotg.c, when|a|^2 < (|a|^2 + |b|^2) * safmin(a is tiny next to b), the sine is computed asThis multiplies
conj(b)by the real part ofaonly. For a complexathe sine has the wrong phase and|c|^2 + |s|^2 != 1. Reference BLAS computess = conjg(g) * (f / d)in this branch.Example:
zrotgwitha = (2^-200, 2^-200)andb = (2^400, 0)returnss = (0.7071, 0)instead of(0.7071, 0.7071).crotgwitha = (2^-30, 2^-30)andb = (2^50, 0)does the same.The fix uses the full complex product, written the same way as in the neighbouring
ada >= h * safminbranch. This branch is separate from the scaled-path sine fixed in #6270 (#6269); the two changes do not overlap.Tests: new
unbalanced_complex_aandc_api_unbalanced_complex_acases inutest/test_extensions/test_crotg.candtest_zrotg.ccheck c, s and r for these inputs through the Fortran and C interfaces. All four fail before the fix (s[1]is 0) and pass after it. I also added myself toCONTRIBUTORS.md.Tested with
make TARGET=HASWELL DYNAMIC_ARCH=0 NO_LAPACK=1 NOFORTRAN=1 NO_SHARED=1 USE_OPENMP=0on Linux x86-64 with GCC 13.3: utest 159 of 159 and utest_ext 1487 of 1487 pass with the fix, and so do the CBLAS tests inctest. Without it, only the four new cases fail. I had no Fortran compiler, so the Fortran BLAS tests and the LAPACK tests did not run.