Skip to content

math: document that Min()/Max() don't agree with builtin min()/max() #60616

@crisman

Description

@crisman

What version of Go are you using (go version)?

https://go.dev/play/?v=gotip
devel go1.21-05293d6b49 Mon Jun 5 14:01:09 2023 +0000

What did you do?

https://go.dev/play/p/Sf_G8Lt9dHy?v=gotip

	x := math.NaN()
	y := math.Inf(-1)

	fmt.Println(min(x, y))
	fmt.Println(math.Min(x, y))

Reports different output.

What did you expect to see?

I expected all output to be NaN.

What did you see instead?

min()/max() are returning NaN and math.Min()/math.Max() are returning -Inf/+Inf.

I think the output of the math versions is wrong as it should check for NaN before the infinities, but I don't have a copy of 754 right now and what min/max is under 754 is special (e.g. see minNum in IEEE 754-2008 vs. minimum & minimumNumber in IEEE 754-2019.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions