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

strconv: Support for Hex Floats (like %a in C) #8072

Closed
gopherbot opened this issue May 22, 2014 · 4 comments
Closed

strconv: Support for Hex Floats (like %a in C) #8072

gopherbot opened this issue May 22, 2014 · 4 comments

Comments

@gopherbot
Copy link

by odysseus9672:

What does 'go version' print?
go version go1.3beta2 +708e129e91a9 Wed May 21 16:01:54 2014 -0700 darwin/amd64

What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.

1. Go does not support the hex encoded floats produceable from the C verb %a in stdio.h
and float.hex/float.fromhex in Python.
2. Example numbers:
pi = 0x1.921fb54442d18p+1
-e = -0x1.5bf0a8b145769p+1
15.39453125 = f.65 = 0x1.eca0000000000p+3
2^-1070 = 0x0.0000000000010p-1022

http://play.golang.org/p/446DOTlpbw

What happened?
A bunch of errors.

What should have happened instead?

Please provide any additional information below.

I know that Go implements an equivalent syntax in the %b verb, but having %a would be
nice for cross compatibility with C, Python, and Java. The best part is that producing
the FormatFloat part of the code is trivial. The tricky part is, as always, getting the
parser to work right.
@ianlancetaylor
Copy link
Contributor

Comment 1:

Given the existence of %b, I don't see an argument for %a.  It's nice to have a syntax
similar to C and Python, but the syntax is already different, and one more difference
doesn't matter.
Leaving this open for strconv issues.

Labels changed: added repo-main, release-none.

@gopherbot
Copy link
Author

Comment 2 by odysseus9672:

Here's the beginning of a function that produces such output. It could use some
prettying up - removal of trailing zeros, the ability to handle flags for field width,
precision, etc.

Attachments:

  1. F64toHex.go (1052 bytes)

@ianlancetaylor
Copy link
Contributor

Comment 3:

Thanks.  The issue tracker is not the place for patches.  Please see
http://golang.org/doc/contribute.html for how to contribute patches.

@robpike
Copy link
Contributor

robpike commented May 29, 2014

Comment 4:

Not worth doing.

Status changed to WorkingAsIntended.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
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

3 participants