Skip to content
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

proposal: Go 2: hexadecimal floats #29008

Open
seebs opened this Issue Nov 29, 2018 · 25 comments

Comments

Projects
None yet
6 participants
@seebs
Copy link
Contributor

seebs commented Nov 29, 2018

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

1.11, but N/A

Does this issue reproduce with the latest release?

Yes.

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

N/A

What did you do?

Read the fmt specs and the language spec, and ponder floating point representation.

What did you expect to see?

Support for hexadecimal floats.

What did you see instead?

No support for hexadecimal floats.

I'm aware that Go's decimal-parsing for floats is superior to that available to C compilers in a number of ways (see issue #12518), but people who want hexadecimal floats often prefer them for reasons beyond that. This does have some overlap with 12518's suggestion for allowing binary exponents with a p suffix, but hexadecimal floats give stronger and easier-to-reason-about guarantees. With decimal representations, it is non-trivial for a human to tell at a glance whether the representation is precise. With hexadecimal floats, the representation is definitionally precise.

Ideally, this would be present in fmt (both for input and output), and also in numeric constants. C used %a/%A, and the format [-]0xh.hhhp[+-]d, with the hexadecimal digits after the period optional, and I don't see any obvious reason to think this specification would cause problems. So far as I know, this wouldn't break any existing code (any valid hex literal would be a syntax error in current go), and it would make life marginally easier for some people doing numerical work.

@gopherbot gopherbot added this to the Proposal milestone Nov 29, 2018

@gopherbot gopherbot added the Proposal label Nov 29, 2018

@ianlancetaylor ianlancetaylor changed the title proposal: hexadecimal floats proposal: Go 2: hexadecimal floats Nov 29, 2018

@seebs

This comment has been minimized.

Copy link
Contributor Author

seebs commented Nov 29, 2018

Someone pointed out that I haven't explained why I don't think Float64FromBits solves this problem.

  1. It's runtime.
  2. It requires you to count a lot of zeroes to write a simple value.
0x1p-3
0.125
Float64FromBits(0x3fc0000000000000)

In this case, obviously decimal is fine, but I am pretty convinced that a hex float literal is way more legible than Float64FromBits for that value.

@josharian

This comment has been minimized.

Copy link
Contributor

josharian commented Dec 1, 2018

Two observations:

With appropriate compiler optimizations, it doesn’t have to be runtime.

If #28493 goes in, the zeros will be easier to count.

@seebs

This comment has been minimized.

Copy link
Contributor Author

seebs commented Dec 1, 2018

So that's a good counterargument to what I said, but I don't feel persuaded, making me think I didn't actually say anything that communicated what I'm looking for. A better way of expressing it might be: I don't want to have to think about the zeroes at all. They're a weird artifact of the normalized representation. Say I want to have a floating-point constant. if I write it as a hex float, I get a 100% predictable float constant that can be used for both float32 and float64, assuming they have sufficient precision, and I know exactly what it means in either of them, and don't have to guess about or think about rounding errors. If I write it in Float##FromBits, I have to have two forms of it because they're different lengths.

Hex floats offer a convenient way to express mantissa values with reliable precision. They are much more human-reader friendly than IEEE's normalized mantissa values, and getting the exponent in decimal, but still in powers of 2, turns out to map nicely onto what's actually happening.

When people first proposed this for C, I was... sort of skeptical. Why would you want floats in hex? That's not how they work! That's not how anything works! But there were enough floating point people on the committee to get it adopted, and I didn't really have an objection, I just didn't see the point. But as I've spent time trying to decipher float values, it's become increasingly clear to me that, while dealing with the whole float as a large unsigned integer certainly works, it's not really easy to read. I can't look at a Float##FromBits value and know what it is without having to do some kind of math in my head. Why is 3fc negative? Because the sign bit for the exponent is the 4, which isn't where I normally look for sign bits, because the 8 is the sign bit for the whole number. Why is a 13-byte string of 0s actually a 1? (Any short punchy explanation is probably wrong.)

It's a lot easier for me to understand "p-3" than "0x3FC". YMMV.

EDIT: I was wrong, though, the 4 isn't the sign bit, the exponent is stored unsigned using a bias of +127. This goes back to my basic assertion that this is not a programmer-friendly way to view float values.

@baryluk

This comment has been minimized.

Copy link

baryluk commented Dec 1, 2018

Some examples:

0x1.FFFFFFFFFFFFFp1023 // double.max
0x1p-52                // double.epsilon
1.175494351e-38F       // float.min
2.645_751
6.022140857E+23
6_022.140857E+20
6_022_.140_857E+20_

Obviously both could be combined.

0x1.F_FFFF_FFFF_FFFFp1_023
@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Jan 17, 2019

We've posted a combined proposal for #19308, #12711, #28493, and #29008 at golang.org/design/19308-number-literals. It includes hex floats as suggested in this issue. (I could have sworn there was an earlier issue proposing hex floats, but I can't find it.)

Note that this will be the first proposal to follow the process outlined in the Go 2 here we come! blog post: we will have everything ready to go and checked in at the start of the Go 1.13 cycle (Feb 1), we will spend the next three months using those features and soliciting feedback based on actual usage, and then at the start of the release freeze (May 1), we will make the "launch decision" about whether to include the work in Go 1.13 or not.

Thanks for your feedback and all your help improving Go.

@seebs

This comment has been minimized.

Copy link
Contributor Author

seebs commented Jan 17, 2019

Thanks! The proposal looks excellent to me.

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Jan 22, 2019

Change https://golang.org/cl/157677 mentions this issue: cmd/compile: accept new Go2 number literals

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Jan 24, 2019

Change https://golang.org/cl/159297 mentions this issue: math/big: permit upper-case 'P' binary exponent (not just 'p')

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Jan 29, 2019

Change https://golang.org/cl/159997 mentions this issue: go/scanner: accept new Go2 number literals

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Jan 29, 2019

Change https://golang.org/cl/160018 mentions this issue: cmd/gofmt: test that Go 2 number literals can be formatted

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Jan 29, 2019

Change https://golang.org/cl/160239 mentions this issue: go/constant: accept new Go2 number literals

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Jan 30, 2019

Change https://golang.org/cl/160240 mentions this issue: go/types: add tests for new Go 2 number literals

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Jan 30, 2019

Change https://golang.org/cl/160247 mentions this issue: fmt: scan new number syntax

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Jan 30, 2019

Change https://golang.org/cl/160242 mentions this issue: strconv: format hex floats

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Jan 30, 2019

Change https://golang.org/cl/160248 mentions this issue: text/template: accept new number syntax

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Jan 30, 2019

Change https://golang.org/cl/160241 mentions this issue: strconv: parse hex floats

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Jan 30, 2019

Change https://golang.org/cl/160245 mentions this issue: fmt: format hex floats and complexes

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Jan 30, 2019

Change https://golang.org/cl/160249 mentions this issue: math/big: add %x float format

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Jan 30, 2019

Change https://golang.org/cl/160184 mentions this issue: cmd/gofmt: normalize number prefixes and exponents

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Jan 30, 2019

Change https://golang.org/cl/160478 mentions this issue: design/19308-number-literals: add note about gofmt

gopherbot pushed a commit that referenced this issue Feb 12, 2019

strconv: parse hex floats
This CL updates ParseFloat to recognize
standard hexadecimal floating-point constants.
See golang.org/design/19308-number-literals for background.

For #29008.

Change-Id: I45f3b0c36b5d92c0e8a4b35c05443a83d7a6d4b3
Reviewed-on: https://go-review.googlesource.com/c/160241
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>

gopherbot pushed a commit that referenced this issue Feb 12, 2019

strconv: format hex floats
This CL updates FormatFloat to format
standard hexadecimal floating-point constants,
using the 'x' and 'X' verbs.

See golang.org/design/19308-number-literals for background.

For #29008.

Change-Id: I540b8f71d492cfdb7c58af533d357a564591f28b
Reviewed-on: https://go-review.googlesource.com/c/160242
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 18, 2019

math/big: permit upper-case 'P' binary exponent (not just 'p')
The current implementation accepted binary exponents but restricted
them to 'p'. This change permits both 'p' and 'P'.

R=Go1.13

Updates golang#29008.

Change-Id: I7a89ccb86af4438f17b0422be7cb630ffcf43272
Reviewed-on: https://go-review.googlesource.com/c/159297
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 18, 2019

cmd/compile: accept new Go2 number literals
This CL introduces compiler support for the new binary and octal integer
literals, hexadecimal floats, and digit separators for all number literals.

The new Go 2 number literal scanner accepts the following liberal format:

number   = [ prefix ] digits [ "." digits ] [ exponent ] [ "i" ] .
prefix   = "0" [ "b" |"B" | "o" | "O" | "x" | "X" ] .
digits   = { digit | "_" } .
exponent = ( "e" | "E" | "p" | "P" ) [ "+" | "-" ] digits .

If the number starts with "0x" or "0X", digit is any hexadecimal digit;
otherwise, digit is any decimal digit. If the accepted number is not valid,
errors are reported accordingly.

See the new test cases in scanner_test.go for a selection of valid and
invalid numbers and the respective error messages.

R=Go1.13

Updates golang#12711.
Updates golang#19308.
Updates golang#28493.
Updates golang#29008.

Change-Id: Ic8febc7bd4dc5186b16a8c8897691e81125cf0ca
Reviewed-on: https://go-review.googlesource.com/c/157677
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 18, 2019

go/scanner: accept new Go2 number literals
This CL introduces go/scanner support for the new binary and octal integer
literals, hexadecimal floats, and digit separators for all number literals.
The new code is closely mirroring the respective code for number literals in
cmd/compile/internal/syntax/scanner.go.

R=Go1.13

Updates golang#12711.
Updates golang#19308.
Updates golang#28493.
Updates golang#29008.

Change-Id: I5315c6aaa7cfc41a618296be20e3acd5114d6b3c
Reviewed-on: https://go-review.googlesource.com/c/159997
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 18, 2019

cmd/gofmt: test that Go 2 number literals can be formatted
R=Go1.13

Updates golang#12711.
Updates golang#19308.
Updates golang#28493.
Updates golang#29008.

Change-Id: Icd25aa7f6e18ed671ea6cf2b1b292899daf4b1a5
Reviewed-on: https://go-review.googlesource.com/c/160018
Reviewed-by: Russ Cox <rsc@golang.org>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 18, 2019

go/constant: accept new Go2 number literals
This CL introduces go/constant support for the new binary and octal integer
literals, hexadecimal floats, and digit separators for all number literals.

R=Go1.13

Updates golang#12711.
Updates golang#19308.
Updates golang#28493.
Updates golang#29008.

Change-Id: I7a55f91b8b6373ae6d98ba923b626d33c5552946
Reviewed-on: https://go-review.googlesource.com/c/160239
Reviewed-by: Russ Cox <rsc@golang.org>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 18, 2019

go/types: add tests for new Go 2 number literals
This CL ensures that go/types can now handle the new
Go 2 number literals. The relevant changes enabling
them in go/types were made in go/constant in the CL
https://golang.org/cl/160239.

R=Go1.13

Updates golang#12711.
Updates golang#19308.
Updates golang#28493.
Updates golang#29008.

Change-Id: I45c1387198fac94769ac59c5301d86b4e1a1ff98
Reviewed-on: https://go-review.googlesource.com/c/160240
Reviewed-by: Russ Cox <rsc@golang.org>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 18, 2019

cmd/gofmt: normalize number prefixes and exponents
Rewrite non-decimal number prefixes to always use a lower-case base
("0X" -> "0x", etc.), and rewrite exponents to use a lower-case 'e'
or 'p'. Leave hexadecimal digits and 0-octals alone.

Comparing the best time of 3 runs of `time go test -run All` with
the time for a gofmt that doesn't do the rewrite shows no increase
in runtime for this bulk gofmt application (in fact on my machine
I see a small decline, probably due to cache effects).

R=Go1.13

Updates golang#12711.
Updates golang#19308.
Updates golang#29008.

Change-Id: I9c6ebed2ffa0a6a001c59412a73382090955f5a9
Reviewed-on: https://go-review.googlesource.com/c/160184
Reviewed-by: Ian Lance Taylor <iant@golang.org>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 18, 2019

text/scanner: accept new Go2 number literals
This CL introduces text/scanner support for the new binary and octal integer
literals, hexadecimal floats, and digit separators for all number literals.
The new code is closely mirroring the respective code for number literals in
cmd/compile/internal/syntax/scanner.go.

Uniformly use the term "invalid" rather than "illegal" in error messages
to match the respective error messages in the other scanners directly.

R=Go1.13

Updates golang#12711.
Updates golang#19308.
Updates golang#28493.
Updates golang#29008.

Change-Id: I2f291de13ba5afc0e530cd8326e6bf4c3858ebac
Reviewed-on: https://go-review.googlesource.com/c/161199
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 18, 2019

strconv: parse hex floats
This CL updates ParseFloat to recognize
standard hexadecimal floating-point constants.
See golang.org/design/19308-number-literals for background.

For golang#29008.

Change-Id: I45f3b0c36b5d92c0e8a4b35c05443a83d7a6d4b3
Reviewed-on: https://go-review.googlesource.com/c/160241
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 18, 2019

strconv: format hex floats
This CL updates FormatFloat to format
standard hexadecimal floating-point constants,
using the 'x' and 'X' verbs.

See golang.org/design/19308-number-literals for background.

For golang#29008.

Change-Id: I540b8f71d492cfdb7c58af533d357a564591f28b
Reviewed-on: https://go-review.googlesource.com/c/160242
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 20, 2019

math/big: permit upper-case 'P' binary exponent (not just 'p')
The current implementation accepted binary exponents but restricted
them to 'p'. This change permits both 'p' and 'P'.

R=Go1.13

Updates golang#29008.

Change-Id: I7a89ccb86af4438f17b0422be7cb630ffcf43272
Reviewed-on: https://go-review.googlesource.com/c/159297
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 20, 2019

cmd/compile: accept new Go2 number literals
This CL introduces compiler support for the new binary and octal integer
literals, hexadecimal floats, and digit separators for all number literals.

The new Go 2 number literal scanner accepts the following liberal format:

number   = [ prefix ] digits [ "." digits ] [ exponent ] [ "i" ] .
prefix   = "0" [ "b" |"B" | "o" | "O" | "x" | "X" ] .
digits   = { digit | "_" } .
exponent = ( "e" | "E" | "p" | "P" ) [ "+" | "-" ] digits .

If the number starts with "0x" or "0X", digit is any hexadecimal digit;
otherwise, digit is any decimal digit. If the accepted number is not valid,
errors are reported accordingly.

See the new test cases in scanner_test.go for a selection of valid and
invalid numbers and the respective error messages.

R=Go1.13

Updates golang#12711.
Updates golang#19308.
Updates golang#28493.
Updates golang#29008.

Change-Id: Ic8febc7bd4dc5186b16a8c8897691e81125cf0ca
Reviewed-on: https://go-review.googlesource.com/c/157677
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 20, 2019

go/scanner: accept new Go2 number literals
This CL introduces go/scanner support for the new binary and octal integer
literals, hexadecimal floats, and digit separators for all number literals.
The new code is closely mirroring the respective code for number literals in
cmd/compile/internal/syntax/scanner.go.

R=Go1.13

Updates golang#12711.
Updates golang#19308.
Updates golang#28493.
Updates golang#29008.

Change-Id: I5315c6aaa7cfc41a618296be20e3acd5114d6b3c
Reviewed-on: https://go-review.googlesource.com/c/159997
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 20, 2019

cmd/gofmt: test that Go 2 number literals can be formatted
R=Go1.13

Updates golang#12711.
Updates golang#19308.
Updates golang#28493.
Updates golang#29008.

Change-Id: Icd25aa7f6e18ed671ea6cf2b1b292899daf4b1a5
Reviewed-on: https://go-review.googlesource.com/c/160018
Reviewed-by: Russ Cox <rsc@golang.org>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 20, 2019

go/constant: accept new Go2 number literals
This CL introduces go/constant support for the new binary and octal integer
literals, hexadecimal floats, and digit separators for all number literals.

R=Go1.13

Updates golang#12711.
Updates golang#19308.
Updates golang#28493.
Updates golang#29008.

Change-Id: I7a55f91b8b6373ae6d98ba923b626d33c5552946
Reviewed-on: https://go-review.googlesource.com/c/160239
Reviewed-by: Russ Cox <rsc@golang.org>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 20, 2019

go/types: add tests for new Go 2 number literals
This CL ensures that go/types can now handle the new
Go 2 number literals. The relevant changes enabling
them in go/types were made in go/constant in the CL
https://golang.org/cl/160239.

R=Go1.13

Updates golang#12711.
Updates golang#19308.
Updates golang#28493.
Updates golang#29008.

Change-Id: I45c1387198fac94769ac59c5301d86b4e1a1ff98
Reviewed-on: https://go-review.googlesource.com/c/160240
Reviewed-by: Russ Cox <rsc@golang.org>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 20, 2019

cmd/gofmt: normalize number prefixes and exponents
Rewrite non-decimal number prefixes to always use a lower-case base
("0X" -> "0x", etc.), and rewrite exponents to use a lower-case 'e'
or 'p'. Leave hexadecimal digits and 0-octals alone.

Comparing the best time of 3 runs of `time go test -run All` with
the time for a gofmt that doesn't do the rewrite shows no increase
in runtime for this bulk gofmt application (in fact on my machine
I see a small decline, probably due to cache effects).

R=Go1.13

Updates golang#12711.
Updates golang#19308.
Updates golang#29008.

Change-Id: I9c6ebed2ffa0a6a001c59412a73382090955f5a9
Reviewed-on: https://go-review.googlesource.com/c/160184
Reviewed-by: Ian Lance Taylor <iant@golang.org>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 20, 2019

text/scanner: accept new Go2 number literals
This CL introduces text/scanner support for the new binary and octal integer
literals, hexadecimal floats, and digit separators for all number literals.
The new code is closely mirroring the respective code for number literals in
cmd/compile/internal/syntax/scanner.go.

Uniformly use the term "invalid" rather than "illegal" in error messages
to match the respective error messages in the other scanners directly.

R=Go1.13

Updates golang#12711.
Updates golang#19308.
Updates golang#28493.
Updates golang#29008.

Change-Id: I2f291de13ba5afc0e530cd8326e6bf4c3858ebac
Reviewed-on: https://go-review.googlesource.com/c/161199
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 20, 2019

strconv: parse hex floats
This CL updates ParseFloat to recognize
standard hexadecimal floating-point constants.
See golang.org/design/19308-number-literals for background.

For golang#29008.

Change-Id: I45f3b0c36b5d92c0e8a4b35c05443a83d7a6d4b3
Reviewed-on: https://go-review.googlesource.com/c/160241
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 20, 2019

strconv: format hex floats
This CL updates FormatFloat to format
standard hexadecimal floating-point constants,
using the 'x' and 'X' verbs.

See golang.org/design/19308-number-literals for background.

For golang#29008.

Change-Id: I540b8f71d492cfdb7c58af533d357a564591f28b
Reviewed-on: https://go-review.googlesource.com/c/160242
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Feb 20, 2019

Change https://golang.org/cl/163079 mentions this issue: text/scanner: don't liberally consume (invalid) floats or underbars

gopherbot pushed a commit that referenced this issue Feb 20, 2019

text/scanner: don't liberally consume (invalid) floats or underbars
This is a follow-up on https://golang.org/cl/161199 which introduced
the new Go 2 number literals to text/scanner.

That change introduced a bug by allowing decimal and hexadecimal floats
to be consumed even if the scanner was not configured to accept floats.

This CL changes the code to not consume a radix dot '.' or exponent
unless the scanner is configured to accept floats.

This CL also introduces a new mode "AllowNumberbars" which controls
whether underbars '_' are permitted as digit separators in numbers
or not.

There is a possibility that we may need to refine text/scanner
further (e.g., the Float mode now includes hexadecimal floats
which it didn't recognize before). We're very early in the cycle,
so let's see how it goes.

RELNOTE=yes

Updates #12711.
Updates #19308.
Updates #28493.
Updates #29008.

Fixes #30320.

Change-Id: I6481d314f0384e09ef6803ffad38dc529b1e89a3
Reviewed-on: https://go-review.googlesource.com/c/163079
Reviewed-by: Ian Lance Taylor <iant@golang.org>

nebulabox added a commit to nebulabox/go that referenced this issue Feb 21, 2019

text/scanner: don't liberally consume (invalid) floats or underbars
This is a follow-up on https://golang.org/cl/161199 which introduced
the new Go 2 number literals to text/scanner.

That change introduced a bug by allowing decimal and hexadecimal floats
to be consumed even if the scanner was not configured to accept floats.

This CL changes the code to not consume a radix dot '.' or exponent
unless the scanner is configured to accept floats.

This CL also introduces a new mode "AllowNumberbars" which controls
whether underbars '_' are permitted as digit separators in numbers
or not.

There is a possibility that we may need to refine text/scanner
further (e.g., the Float mode now includes hexadecimal floats
which it didn't recognize before). We're very early in the cycle,
so let's see how it goes.

RELNOTE=yes

Updates golang#12711.
Updates golang#19308.
Updates golang#28493.
Updates golang#29008.

Fixes golang#30320.

Change-Id: I6481d314f0384e09ef6803ffad38dc529b1e89a3
Reviewed-on: https://go-review.googlesource.com/c/163079
Reviewed-by: Ian Lance Taylor <iant@golang.org>

gopherbot pushed a commit that referenced this issue Feb 26, 2019

fmt: format hex floats and complexes
This CL modifies fmt's printer to implement %x and %X
for formatting floating-point data (floats and complexes)
in standard hexadecimal notation.

See golang.org/design/19308-number-literals for background.

For #29008.
Vet update is #29986.

Change-Id: If2842a11631bc393a1ebcf6914ed07658652af5a
Reviewed-on: https://go-review.googlesource.com/c/160245
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Rob Pike <r@golang.org>

gopherbot pushed a commit that referenced this issue Feb 26, 2019

fmt: scan new number syntax
This CL updates fmt's scanner to accept the new number syntaxes:

 - Hexadecimal floating-point values.
 - Digit-separating underscores.
 - Leading 0b and 0o prefixes.

See golang.org/design/19308-number-literals for background.

For #12711.
For #19308.
For #28493.
For #29008.

Change-Id: I5582af5c94059c781e6cf4e862441d3df3006adf
Reviewed-on: https://go-review.googlesource.com/c/160247
Reviewed-by: Robert Griesemer <gri@golang.org>

gopherbot pushed a commit that referenced this issue Feb 26, 2019

text/template: accept new number syntax
This CL updates text/template's scanner to accept the
new number syntaxes:

 - Hexadecimal floating-point values.
 - Digit-separating underscores.
 - Leading 0b and 0o prefixes.

See golang.org/design/19308-number-literals for background.

For #12711.
For #19308.
For #28493.
For #29008.

Change-Id: I68c16ea35c3f506701063781388de72bafee6b8d
Reviewed-on: https://go-review.googlesource.com/c/160248
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>

gopherbot pushed a commit that referenced this issue Feb 26, 2019

math/big: add %x float format
big.Float already had %p for printing hex format,
but that format normalizes differently from fmt's %x
and ignores precision entirely.

This CL adds %x to big.Float, matching fmt's behavior:
the verb is spelled 'x' not 'p', the mantissa is normalized
to [1, 2), and precision is respected.

See golang.org/design/19308-number-literals for background.

For #29008.

Change-Id: I9c1b9612107094856797e5b0b584c556c1914895
Reviewed-on: https://go-review.googlesource.com/c/160249
Reviewed-by: Robert Griesemer <gri@golang.org>

gopherbot pushed a commit that referenced this issue Mar 12, 2019

spec: document new Go2 number literals
This CL documents the new binary and octal integer literals,
hexadecimal floats, generalized imaginary literals and digit
separators for all number literals in the spec.

Added empty lines between abutting paragraphs in some places
(a more thorough cleanup can be done in a separate CL).

A minor detail: A single 0 was considered an octal zero per the
syntax (decimal integer literals always started with a non-zero
digit). The new octal literal syntax allows 0o and 0O prefixes
and when keeping the respective octal_lit syntax symmetric with
all the others (binary_lit, hex_lit), a single 0 is not automatically
part of it anymore. Rather than complicating the new octal_lit syntax
to include 0 as before, it is simpler (and more natural) to accept
a single 0 as part of a decimal_lit. This is purely a notational
change.

R=Go1.13

Updates #12711.
Updates #19308.
Updates #28493.
Updates #29008.

Change-Id: Ib9fdc6e781f6031cceeed37aaed9d05c7141adec
Reviewed-on: https://go-review.googlesource.com/c/go/+/161098
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.