golang/go

cmd/gc: compiler must not accept p-notation floats in regular Go code

griesemer opened this issue · 12 comments

gc accepts the p-notation for floating point numbers:

mantissa "p" exponent

such as 12p-2, etc.

http://play.golang.org/p/xOixorUxUD

The spec doesn't mention them. gccgo and go/types don't support them.

a) we should either disallow them, or
b) we should support them with consistent syntax and document them.

Comment 1:

I can go either way but I would be ok supporting them.
If we do, I propose one of these productions:
pfloat_lit = int_lit ( "p" | "P" ) [ "+" | "-" ] decimals .
or
pfloat_lit = decimal_lit ( "p" | "P" ) [ "+" | "-" ] decimals .
i.e., if we permit non-decimal mantissa, we should permit any integer notation.

Comment 2:

Why does gc accept this? Is it needed for export data only?

Comment 3:

It's plausible that it's an export data relict - I don't know of std lib code that needs
this.
rsc commented

Comment 4:

It's for export data. It's not supposed to be generally available.
rsc commented

Comment 5:

Will fix for Go 1.5. It's been there basically forever; no harm in leaving it in for Go
1.4.
rsc commented

Comment 6:

Labels changed: removed documentation, languagechange.

There are several related errors:

http://play.golang.org/p/VVK5tF24e2

  • p exponent
  • hex mantissa and p exponent
  • hex mantissa and e exponent interpreted as int

What is this "export data"? I've been trying to figure out the conditions under which 'p' and 'P' etc should not be rejected?

"Export data" is the textual (go-syntax like) representation of the package "objects" that are exported from the package. The export data of a package A is parsed when another package B imports A. The export data can be found in the object/archive file.

The p-format is used to read and write floating-point numbers quickly and accurately without the need to convert to a decimal exponent.

@dr2chase see also the go/internal/gcimporter package and cmd/compile/internal/gc/export.go

CL https://golang.org/cl/10450 mentions this issue.