Skip to content

spec: imprecise language around min and max when considering NaN #60570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
btracey opened this issue Jun 2, 2023 · 7 comments
Closed

spec: imprecise language around min and max when considering NaN #60570

btracey opened this issue Jun 2, 2023 · 7 comments
Labels
Documentation Issues describing a change to documentation. FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@btracey
Copy link
Contributor

btracey commented Jun 2, 2023

The go spec at tip has the following language about min and max

For numeric arguments, min and max are commutative and associative:

min(x, y)    == min(y, x)
min(x, y, z) == min(min(x, y), z) == min(x, min(y, z))

In my reading, this is insufficiently precise. In particular, min(math.NaN()) == min(math.NaN()) is false, so currently the spec is impossible to satisfy (cannot both propogate NaN and have those expressions be true). There should be a clarification around the interaction of NaN and ==.

@mknyszek mknyszek added Documentation Issues describing a change to documentation. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jun 2, 2023
@mknyszek mknyszek added this to the Go1.21 milestone Jun 2, 2023
@mknyszek
Copy link
Contributor

mknyszek commented Jun 2, 2023

CC @griesemer who wrote the spec update for this.

@mknyszek mknyszek changed the title spec: Language confusing around "numeric arguments" for min and max spec: imprecise language around "numeric arguments" for min and max for NaN Jun 2, 2023
@mknyszek mknyszek changed the title spec: imprecise language around "numeric arguments" for min and max for NaN spec: imprecise language around min and max when considering NaN Jun 2, 2023
@griesemer
Copy link
Contributor

NaN which stands for "Not a Number" is not a number, and thus arguably not a numeric argument...

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/500416 mentions this issue: spec: clarify min/max rules for numeric arguments (exclude NaNs)

@btracey
Copy link
Contributor Author

btracey commented Jun 2, 2023 via email

@crisman
Copy link
Contributor

crisman commented Jun 4, 2023

This is already covered in the text given, "For numeric arguments" which means NaN is not covered in that section.

The next line after the original quoted text gives the chart:

For floating-point arguments negative zero, NaN, and infinity the following rules apply:

Also min(math.NaN()) == min(math.NaN()) is correct as math.NaN() == math.NaN() is false and the spec says "Two floating-point values are compared as defined by the IEEE-754 standard." and that is how 754 works. We can't import 754 like that and then say using it in another section is broken.

@crisman
Copy link
Contributor

crisman commented Jun 5, 2023

Meh, my brain is clearly not up to speed as float64 is numeric and NaN is float64 so my last comment does not make sense. Sorry about the added confusion.

@crisman
Copy link
Contributor

crisman commented Jun 6, 2023

Related oddity for NaN in #60616.

@golang golang locked and limited conversation to collaborators Jun 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation Issues describing a change to documentation. FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants