Skip to content

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

@gopherbot

Description

@gopherbot

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions