mirror of
https://github.com/golang/go
synced 2024-11-15 00:20:30 -07:00
ceb849dd97
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 #12711. Updates #19308. Updates #28493. Updates #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>
32 lines
775 B
Go
32 lines
775 B
Go
// errorcheck
|
|
|
|
// Copyright 2015 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Expects to see error messages on 'p' exponents
|
|
// for non-hexadecimal floats.
|
|
|
|
package main
|
|
|
|
import "fmt"
|
|
|
|
const (
|
|
x1 = 1.1 // float
|
|
x2 = 1e10 // float
|
|
x3 = 0x1e10 // integer (e is a hex digit)
|
|
)
|
|
|
|
const x4 = 0x1p10 // valid hexadecimal float
|
|
const x5 = 1p10 // ERROR "'p' exponent requires hexadecimal mantissa"
|
|
const x6 = 0P0 // ERROR "'P' exponent requires hexadecimal mantissa"
|
|
|
|
func main() {
|
|
fmt.Printf("%g %T\n", x1, x1)
|
|
fmt.Printf("%g %T\n", x2, x2)
|
|
fmt.Printf("%g %T\n", x3, x3)
|
|
fmt.Printf("%g %T\n", x4, x4)
|
|
fmt.Printf("%g %T\n", x5, x5)
|
|
fmt.Printf("%g %T\n", x6, x6)
|
|
}
|