Skip to content

math: MaxFloat32/64 and SmallestNonzeroFloat32/64 value comments misleading #61230

@extemporalgenome

Description

@extemporalgenome

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

Playground 1.20 as of Fri Jul 7 15:17:35 UTC 2023.

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

Playground

What did you do?

https://go.dev/play/p/HZ_Nr7FpU9d

strconv.FormatFloat(math.MaxFloat64, 'e', -1, 64)

What did you expect to see?

1.79769313486231570814527423731704356798070e+308

(since this longer value is listed in the doc comment for math.MaxFloat64)

What did you see instead?

1.7976931348623157e+308

This applies to MaxFloat32, MaxFloat64, SmallestNonzeroFloat32, and SmallestNonzeroFloat64.

Since all of these cases are rational numbers defined in terms of the type itself, I expect their doc comments to have exactly the same value that strconv.FormatFloat would produce with -1 precision.

Note that C# (link) and Java (link) also express the constant in terms of the value that strconv.FormatFloat prints with -1 precision.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions