Skip to content

[basic.fundamental] It is unclear whether negative zero is negative #817

@eisenwave

Description

@eisenwave

Reference (section label): [basic.fundamental]

Issue description

#include <complex>
auto c = std::polar(std::copysign(0.0, -1.0));

If negative zero is negative, the Preconditions element of std::polar is not satisfied, and the behavior is undefined. However, the intent is for negative zero and positive zero to be largely interchangeable.

C23 5.2.4.2.2 [Characteristics of floating types <float.h>] clarifies as follows:

A value is negative if and only if it compares less than 0. Thus, negative zeros and NaNs are not negative values.

Library wording such as in [tab:format.sign] already treats negative zero as distinct from the negative numbers:

Indicates that a sign should be used for negative numbers and negative zero only (this is the default behavior).

Suggested resolution

Immediately prior to [basic.fundamental] paragraph 14, insert a new paragraph:

+? A value is negative if and only if it compares less than 0.
+Thus, negative zeros and NaNs are not negative values.

 14 Integral and floating-point types are collectively termed arithmetic types.

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