Skip to content

fmaximum/minimum_num incorrect result for -0/+0 #139481

Open
@gonzalobg

Description

@gonzalobg

See https://clang.godbolt.org/z/3W6f9faaK
Reproduced below.
When the inputs of C23 maximum/minimum_num are -0 and +0, it always returns +0.
However, clang returns -0.

#include <cmath>
#include <print>

int main() {
    using T = double;
    T nz = T(-0.);
    T pz = T(+0.);
    T r = fmaximum_num(pz,nz);
    int v = std::memcmp(&r, &pz, sizeof(double)); // if result bitwise identical to +0, then returns 0
    if (v == 0) return 0;
    std::println(stderr, "ERROR: {} != {}", r, pz); // prints 0 != -0
    return 1;
}

cc @lntue

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions