Skip to content

[expr.rel] It is unclear whether positive zeros compare equal to negative zeros #814

@eisenwave

Description

@eisenwave

Reference (section label): [expr.rel]

Issue description

The C++ standard acknowledges the existence of positive and negative zeros such as in [atomics.types.float], but does not specify whether these distinct values compare equal. Note that std::signbit lets the user observe a difference between these values.

C23 6.5.8 [Relational operators] paragraph 4 clarifies this:

Positive zeros compare equal to negative zeros.

Suggested resolution

Change in [expr.spaceship] paragraph 4 bullet 3 as follows:

 Otherwise, the operands have floating-point type,
 and the result is of type std​::​partial_ordering.
 The expression a <=> b yields
 std​::​partial_ordering​::​less if a is less than b,
 std​::​partial_ordering​::​greater if a is greater than b,
 std​::​partial_ordering​::​equivalent if a is equivalent to b, and
 std​::​partial_ordering​::​unordered otherwise.
+Positive zeros are equivalent to negative zeros.

Change in [expr.rel] paragraph 6 as follows:

 If both operands (after conversions) are of arithmetic or enumeration type,
 each of the operators shall yield true if the specified relationship is true and
 false if it is false.
+Positive zeros compare equal to negative zeros.

Change in [expr.eq] paragraph 8 as follows:

 If both operands are of arithmetic or enumeration type,
 the usual arithmetic conversions ([expr.arith.conv]) are performed on both operands;
 each of the operators shall yield true if the specified relationship is true and
 false if it is false.
+Positive zeros compare equal to negative zeros.

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