Skip to content

xLANGE underflows for finite 1x2 matrix #565

@christoph-conrads

Description

@christoph-conrads

Description

SLANGE underflows for 1x2 matrices of the form [μ, 0], where μ is the smallest normal floating-point value. The overflow occurs when SCOMBSSQ sums the Euclidean norms of the individual columns. I expect SLANGE not to underflow for the given input. (Curiously enough, overflows in SLANGE were recently fixed.)

// Copyright 2021 Christoph Conrads

#include <cmath>
#include <cstddef>
#include <cstdint>
#include <cstdio>

#include <limits>

using Integer = std::int32_t;

extern "C" {
    float slange_(
        char* norm, Integer* m, Integer* n, const float* A, Integer* lda,
        float* work, std::size_t norm_len);
}



int main() {
    using Real = float;

    auto normid = 'F';
    auto m = Integer{1};
    auto n = Integer{2};
    auto min = std::numeric_limits<Real>::min();
    Real a[] = {min, 0};
    auto lda = m;
    auto work = std::numeric_limits<Real>::quiet_NaN();
    auto norm = slange_(&normid, &m, &n, a, &lda, &work, 1);

    if(!std::isfinite(norm) || norm != min) {
        std::fprintf(
            stderr, "expected norm %8.2e, got %e\n", min, norm);
    }
}

Output on Ubuntu 20.04:

/tmp/build.lapack $ g++ -Wextra -Wall -pedantic -std=c++11 ~/slange-underflow.cpp -Llib -llapack -g
/tmp/build.lapack $ env LD_LIBRARY_PATH="$PWD/lib" ./a.out 
expected norm 1.18e-38, got 0.000000e+00
/tmp/build.lapack $ git -C ~/lapack/ rev-parse HEAD
1c8d81aae95c6bb5d563d7e585f15af569a67ed0

Checklist

  • I've included a minimal example to reproduce the issue
  • I'd be willing to make a PR to solve this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions