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

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

Closed
griesemer opened this issue Oct 31, 2014 · 12 comments
Closed
Milestone

Comments

@griesemer
Copy link
Contributor

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.
@griesemer
Copy link
Contributor Author

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.

@robpike
Copy link
Contributor

robpike commented Oct 31, 2014

Comment 2:

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

@griesemer
Copy link
Contributor Author

Comment 3:

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

@rsc
Copy link
Contributor

rsc commented Nov 3, 2014

Comment 4:

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

@rsc
Copy link
Contributor

rsc commented Nov 3, 2014

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
Copy link
Contributor

rsc commented Nov 3, 2014

Comment 6:

Labels changed: removed documentation, languagechange.

@bradfitz bradfitz modified the milestone: Go1.5 Dec 16, 2014
@griesemer
Copy link
Contributor Author

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

@dr2chase
Copy link
Contributor

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

@minux
Copy link
Member

minux commented May 27, 2015 via email

@griesemer
Copy link
Contributor Author

"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.

@josharian
Copy link
Contributor

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

@gopherbot
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants