-
Notifications
You must be signed in to change notification settings - Fork 74
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 support for %a,%A format specifiers - hex float output #17 #53
Conversation
Add tests for formatted output, width modifier and precision (NA). Fix two typos.
So, all the Windows appveyor CI platforms are failing on tests |
Thanks this looks great. We'll need to dig into the CI issues but other than that LGTM. |
I added the |
Ok there you go: the tests are failing due to older MSVC generating extra zero padding. Is there a way to work around that? That also makes me wonder whether we need a test for long fractional part with |
Stream output of hexfloat should ignore stream precision. This change cooks the tests so that they output exactly the default 6 hexits
According to STL (himself) this sounds like an MSVC bug |
Still fails on VS 12 where precision(0) means 0. |
The format string specifies precision as "%.13a" so that the test will pass on MSVC.
Good idea. 13 hexits, at 4 bits per hexit, corresponds exactly to the 52-bit significand of an
I was wondering whether we should disallow precision spec in the %a format string. |
Sorry for the slow response, I've been away on holiday.
My guiding principle: what do otherwise conforming Regarding non-conforming MSVC versions, I think we should simply force precision to 13 digits for MSVC to ensure the primary(?) goal of hexfloat: guaranteed round-trippable conversions. If the resulting strings contain a few extra zeros, so be it (the files will be a bit bigger, but nothing will break). |
Force precision to 13 in this case to guarentee roundtripping of double precision hexfloat formatted numbers with MSVC.
Ok, I've pushed some changes which implement my suggested workaround for MSVC. I hope this will do the trick now. |
Ok tests have passed finally. I think this could be merged if the current version satisfies your use case? |
Looks good to me. |
Merged! |
I'd missed some of action here so thanks for going ahead. The workaround for MSVC, conditional compile setting full precision, is the best that can be done for now. |
I hope what I ended up with works for you. I've always resisted writing my own conversion code because that seems to be a massive rabbit hole which I don't want to go down. Besides, other excellent libraries have the "let's write a lot of code so we can just do printf safely and as fast as possible" niche covered. The flip side of trying to be minimal is having to put up with some bugs, as here... |
Add tests for formatted output, width modifier and precision (ignored).
(Only tested on recent GCC so please test with the CI targets.)