You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(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.
The text was updated successfully, but these errors were encountered:
Why doesn't math.MaxFloat32exactly represent the maximum finite value that can be stored in a float32? It may happen to produce the maximum-finite bit-pattern when stored in a float32, but is it still reasonable to claim that this is the maximum finite value that a float32 holds when it's not exactly that same finite value?
The special precision -1 uses the smallest number of digits necessary such that ParseFloat will return f exactly.
So the "actual" you're generating here is not the actual value contained in the float. It is the shortest possible string that parses to that float.
fmt.Println I think also does not print with arbitrary precision. (It prints with "default format", whatever that means.)
If you print with %.0f it will give you the exact value. The resulting value is what is listed in comments for float32, and probably would be listed for float64 only it is too long.
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
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
, andSmallestNonzeroFloat64
.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 thatstrconv.FormatFloat
prints with -1 precision.The text was updated successfully, but these errors were encountered: