-
-
Notifications
You must be signed in to change notification settings - Fork 727
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
Partial replace call to snprintf for formating floatingpoint numbers. #7264
Conversation
The failure on eBay/tsv-utils is due to the different tie in rounding. This is intentional (I think the new version is better) but might be discussed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has not gotten enough testing. Try double.max (1.0/3.0) inf -inf machine epsilon pi 2pi and a few other well known constants, at the very least.
There are only 2^32 float so you could do an exhaustive check there. (I don't mean in a commited unittest) |
I did that allready with two different format strings - see pdf. |
inf (line 7743/7744) and epsilon (line 7788) are allready in the unittests. I'll add max and some special constants. |
Thanks for your pull request and interest in making D better, @berni44! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#7264" |
added more unittests (and sorry @UplinkCoder I overlooked, that the eps-tests where float not double, added the double tests now) |
While working on |
Just to say that this seems like fantastic work if the PDF says the truth. For localization I also think it fixes more undiscovered bugs than it breaks (there are more people unaware of localization using snprintf unknowingly, than people using D and relying on printf localization) |
Thanks for compliment! :-) If you want to check the content of the pdf: I put all needed functions in the repo and would be happy, if someone could verify the results... |
Changed tie for rounding to the current behaviour. I'll address this later in a separate PR. I also added improvements suggested in PR #7285. |
Does anyone has an idea, what this 32bit-windows compiler bug is about? |
Merged everything and run the external tests (for %f and %a): all passed. I changed bias from long to int, because I guess, this is the reason, why win32 crashed after the last change (had something similar resently in an other PR, as far as I remember). Let's see... I also unified the tests for large precissions. I think there is no merit in having a string literal, which essentially consists of 1000 zeros in the source code. For checking the bug, it's sufficient to just check the length. |
Fixed problem with global import of |
Fixed the merge conflicts. |
std/format.d
Outdated
return printFloatA(val, f, rm, sgn, exp, mnt, is_upper); | ||
case 'e': case 'E': | ||
return printFloatE(val, f, rm, sgn, exp, mnt, is_upper); | ||
case 'f': case 'F': | ||
return printFloatF(val, f, rm, sgn, exp, mnt, is_upper); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the success of the float zero factorisation, I'm beginning to think that the best way to organise the printing is not by format specifier (%a,%f,%g,%e) but by "category" (for want of a better term), i.e.
- inf/nan (handled above),
- Algorithm A: For large exponents (exp >= T.mant_dig)
- Algorithm B: For small exponents (exp < T.mant_dig - 61)
- Algorithm C: For exponents close to 0. (already done)
Since there seems to be much more in common between the different ranges of numbers than there is between the different format specifiers.
Currently, only the format specifiers f and F are supported and only float and double.
Rebased and adapted to not allocate as in #7393 |
Implemented in another PR |
I'm not following phobos development closely, but which one would that be? |
#7393 No? |
Do you anyone can push this forward @rainers or @thewilsonator ? This PR is crucial to have purity on |
Closing this in favor of #7757 |
Because the description of this PR is long and contains diagrams, I put everything into printFloat.pdf.
TL;DR: Read only the abstract.
Still TL;DR: This only replaces the 'f' specifier for float and double. The algorithm is correct, in most cases faster than the old one (some optimizations are still WIP), it implements rounding according to IEEE754 (with a different tie than the old one), but no internationalisation, because that causes a lot of trouble and should be done elsewhere.