]> Cypherpunks repositories - gostls13.git/commitdiff
fmt: document how %#g handles infinities and NaNs
authorRob Pike <r@golang.org>
Sun, 21 Jan 2024 06:20:02 +0000 (17:20 +1100)
committerRob Pike <r@golang.org>
Tue, 13 Feb 2024 01:04:30 +0000 (01:04 +0000)
The %#g format prints a "Go-syntax representation", but there is
no such thing for IEEE754 infinities and NaNs, so just document
what happens, which is that it prints +Inf, -Inf, or NaN.  We could
show something like math.Inf(1) and math.Nan(), but that doesn't
sit right, and anyway for NaNs you can't even recover the original
value. Simpler and more honest to give up.

Fixes #51486

Change-Id: I8d4e8186f5d7acc3e0e7b51d0b322142908ea0a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/557235
Run-TryBot: Rob Pike <r@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/fmt/doc.go

index ea2da97da6299780da265cc0af2631f1595e9390..c47bee108036a04170e4e3db1e8f070e64daa80f 100644 (file)
@@ -16,6 +16,7 @@ General:
        %v      the value in a default format
                when printing structs, the plus flag (%+v) adds field names
        %#v     a Go-syntax representation of the value
+               (floating-point infinities and NaNs print as ±Inf and NaN)
        %T      a Go-syntax representation of the type of the value
        %%      a literal percent sign; consumes no value