Skip to content

CROTG/ZROTG return wrong sine phase for scaled complex inputs after #6123 #6269

Closed

Description

@wonwondogs

Summary

On current develop (dbf2c24c9e43ed8f8c12f32837a2f87fab848e97), cblas_zrotg and cblas_crotg return the wrong imaginary sign for the sine when finite complex inputs take the scaled path. The resulting rotation does not annihilate the second component.

This appears to be a regression from #6123. The ZROTG cases I checked from #6120 pass on current develop, but the mixed-phase case below does not.

Reproducer

Link this program against a current OpenBLAS build. The inputs are finite normal numbers and exact powers of two.

#include <math.h>
#include <stdio.h>
#include <cblas.h>

int main(void) {
    double a[2] = {0x1p512, 0.0};
    double b[2] = {0x1p512, 0x1p512};
    double c, s[2];
    cblas_zrotg(a, b, &c, s);
    printf("ZROTG: c=%.17g s=(%.17g,%.17g) second/2^512=(%.17g,%.17g)\n",
           c, s[0], s[1], c - s[0], c + s[1]);

    float af[2] = {0x1p70f, 0.0f};
    float bf[2] = {0x1p70f, 0x1p70f};
    float cf, sf[2];
    cblas_crotg(af, bf, &cf, sf);
    printf("CROTG: c=%.9g s=(%.9g,%.9g) second/2^70=(%.9g,%.9g)\n",
           cf, sf[0], sf[1], cf - sf[0], cf + sf[1]);

    return fabs(c + s[1]) > 1e-12 || fabsf(cf + sf[1]) > 1e-5f;
}

For ZROTG, the expected result is c = 1/sqrt(3) and s = (1-i)/sqrt(3), so second/2^512 = (c-Re(s), c+Im(s)) is approximately (0,0). The bundled Reference BLAS ZROTG returns this result.

Current OpenBLAS returns c = 0.57735026918962573 and s = (0.57735026918962584, +0.57735026918962584), giving second/2^512 ≈ (-1.1e-16, 1.1547005383792515). CROTG has the same sign error at the smaller scale shown above.

Environment

  • OpenBLAS develop at dbf2c24c9e43ed8f8c12f32837a2f87fab848e97, built from source and linked as a static library
  • Apple M5 Pro, macOS 27.0; the reproducer calls only the scalar ROTG routines

Suspected cause

In interface/zrotg.c near line 164, the scaled branch computes the imaginary part of s with - gs_i * -1. * (fs_r / f2h), which adds that term. For f * conj(g), this term should be subtracted. The expression was changed in #6123 while fixing #6120. The source is shared by the single- and double-precision routines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions