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

add hexfloat (%a) support for printf #8729

Merged
merged 1 commit into from
Nov 10, 2014

Conversation

simonbyrne
Copy link
Contributor

This should match the behaviour of c99 standard (page 291).

@StefanKarpinski
Copy link
Sponsor Member

This is quite impressive. I should probably give it a serious read-through, but it looks overall good.

@simonbyrne
Copy link
Contributor Author

It is based on the %e implementation, though it needed a few tweaks to deal with the auto-truncation behaviour.

The spec doesn't say how to choose the leading digit. I've implemented the gcc behaviour which uses a leading 1 most of the time (though we differ on handling of subnormals):

julia> @printf "%a" 9.0
0x1.2p+3

MPFR on the other hand appears to choose the leading digit to match the integer representation:

julia> @printf "%a" big(9.0)
0x9p+0

Not sure if it matters?

@StefanKarpinski
Copy link
Sponsor Member

Ouch, that's annoying that they don't agree. Printing the same value in different types should really produce the same result :-. Not sure how best to address that though.

@simonbyrne
Copy link
Contributor Author

From what I can tell, gcc tries to closely represent the underlying bit structure: hence the leading 1 for most numbers, and for subnormals it prints things like 0x0.0000000000001p-1022.

nolta added a commit that referenced this pull request Nov 10, 2014
add hexfloat (%a) support for printf
@nolta nolta merged commit c4a4568 into JuliaLang:master Nov 10, 2014
@simonbyrne simonbyrne deleted the hexfloat-printf branch March 10, 2015 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants