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

math/big: make Float implement encoding.TextMarshaler and encoding.TextUnmarshaler interfaces #12256

Closed
kostya-sh opened this issue Aug 21, 2015 · 4 comments
Milestone

Comments

@kostya-sh
Copy link
Contributor

Both big.Int and big.Rat have MarshalText and UnmarshalText methods to implement two interfaces from encoding package: TextMarshaler and TextUnmarshaler.

big.Float should implement these interfaces as well

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Aug 21, 2015
@gopherbot
Copy link

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

@kostya-sh
Copy link
Contributor Author

Implementing these interfaces is less trivial than it seems.

Fast and looseless implementation could use hexadecimal notation with 'p' (binary) exponent. But it depends about the expectations of MarshalText: Should it always return a string representation that is a "standard" floating-point number that might be read by another system? In that case, the 'p' notation might not be option.

An implementation that is more similar to float32/64 can use 'g' with precision -1 (once implemented) but it's a very expensive conversion. Additionally currently there is no way to parse a string without loosing precision. Parse's semantic may actually not be correct as is: It perhaps should parse w/o rounding error if the precision is 0.

@griesemer
Copy link
Contributor

Decided to keep it simple for now and implement this simply via the 'g' with precision -1 format. Also, no recording of precision or accuracy. This makes this work for json w/o trouble.

@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Sep 28, 2016
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

4 participants