Skip to content

Conversation

@eisenwave
Copy link
Member

@eisenwave eisenwave commented Nov 19, 2025

This is branching off from cplusplus/CWG#814 (comment)

There are various mentions of NaNs, positive and negative zeros, infinities, etc. scattered throughout the standard. We do a bad job of comprehensively listing these possibilities in one place.

It's also not obvious whether we consider floating-point types to require having a positive and negative zero, positive and/or negative infinity, NaN values, and whatnot. This is really difficult to figure out.

My understanding of the wording is that floating-point types are only guaranteed to represent some rational numbers; anything else, such as NaNs, infinities, negative zeros, etc. may or may not exist, based on the representation of float chosen by the implementation.

@eisenwave eisenwave added the P3-Other Triaged issue not in P1 or P2 label Nov 19, 2025
@eisenwave eisenwave force-pushed the acknowledge-zero-sign branch from 87188f1 to 852d447 Compare November 20, 2025 07:01
@eisenwave eisenwave force-pushed the acknowledge-zero-sign branch 2 times, most recently from 2001f63 to 20426f9 Compare November 20, 2025 09:08
source/basic.tex Outdated
A floating-point type shall at least represent a subset of rational numbers
called \defnadjx{finite}{values}{value}.
Depending on the implementation-defined value representation for the type,
it may additionally represent the finite value negative zero,
Copy link
Member

@jwakely jwakely Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talking about negative zero as distinct from the other zero implies that the other one is naturally positive, but mathematically that's not true. It's true for IEEE floats but not mathematics. It might be better to talk about zero being signed, rather than saying there can also be negative zero.

I haven't come up with a good way to phrase that though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe say something like there are finite values, and maybe infinities, and NaNs, and they might all have a sign, including zero.

Copy link
Member Author

@eisenwave eisenwave Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N5014 already uses "negative zero" 9 times, and C has some mentions of it too. It doesn't make much mathematical sense, but I really don't see how we could avoid saying "negative zero" when that's the established term of the last 30 years; we use that anywhere else.

We also mention "negative NaN values" in [cmp.alg].

cplusplus/CWG#817 clarifies that neither negative NaNs nor negative zero are negative values. I can see how this is all a bit paradoxical and unhelpful, but I wouldn't be comfortable with avoiding this terminology only in [basic.fundamental].

Copy link
Member

@jwakely jwakely Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My objection isn't to mentioning negative zero at all, only in this context of something definition-like where you're mentioning it in addition to some other value, which either implies we have "zero and negative zero" or that it's just obvious that the other one is positive zero. But neither of those things is so obviously true that it doesn't need clarifying. A floating-point type might just have a zero value (or several equivalent zero values), without any sign, or it might have signed zeros, in which case it has both positive zero and negative zero. So I think introducing negative zero should be in the context of zero being (possibly, depending on the implementation) signed. Because that implies a positive zero too, not just "real zero and some negative zero thing".

Copy link
Member

@jwakely jwakely Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I.e. the existence of negative zero in the IEEE formats is a direct consequence of zero (and all other values) having a sign bit.

I've just discovered that C23 now requires a sign bit for all values:
https://cigix.me/c23#5.2.5.3.3.p8

C17 didn't:
https://cigix.me/c17#5.2.4.2.2.p4

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes sense to normatively refer to positive zero, because a format that doesn't have a signed zero doesn't have positive zero, it just has zero.

Now if we follow C23 and require signed zeros, that isn't a problem - but that would be a normative change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think I figured out a way to phrase it. The new wording says that any one of those values listed may have two distinct negative/positive versions.

By using the word "distinct", it's still clear that those aren't two identical values that have a quasi-padding sign bit, but that they are technically distinct values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I.e. the existence of negative zero in the IEEE formats is a direct consequence of zero (and all other values) having a sign bit.

I've just discovered that C23 now requires a sign bit for all values: https://cigix.me/c23#5.2.5.3.3.p8

C17 didn't: https://cigix.me/c17#5.2.4.2.2.p4

I misread the new C23 wording, it still allows unsigned zero. "Floating types shall be able to represent signed zeros or an unsigned zero"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and I assume we don't change that in any way? The currently proposed paragraph seems to be fine then.

@eisenwave eisenwave force-pushed the acknowledge-zero-sign branch from 20426f9 to 0dcac5f Compare November 20, 2025 09:47
@eisenwave eisenwave force-pushed the acknowledge-zero-sign branch from 0dcac5f to 17545cb Compare November 20, 2025 10:42
@jensmaurer jensmaurer added cwg Issue must be reviewed by CWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking. labels Nov 21, 2025
@jensmaurer
Copy link
Member

I hope it's clear we're not adding normative stuff ("shall") using an editorial issue.

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

Labels

cwg Issue must be reviewed by CWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking. P3-Other Triaged issue not in P1 or P2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants