Skip to content

Conversation

ghost
Copy link

@ghost ghost commented Nov 17, 2019

This is a followup on #7264. This time it implements %a and %A specifiers. Part of this is identical to #7264 to make this PR independed.

I run essentially the same tests as in #7264.

Concerning correctness: All tests passed. There where two exceptions:
a) There is a bug for denormalized floats in snprintf. The new version fixes this.
b) Ties for roundToNearest are different, like in #7264.

Concerning speed: dmd is a little bit slower with the new version, while ldc2 is slightly faster. See pdf-file for some diagrams.

@ghost ghost requested a review from andralex as a code owner November 17, 2019 20:30
@dlang-bot
Copy link
Contributor

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 verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

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

Auto-close Bugzilla Severity Description
20371 normal std.format limited to 500 characters for floats
20396 normal format!"%a" leeds to wrong result for denormalized float

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + phobos#7285"

@ghost
Copy link
Author

ghost commented Dec 4, 2019

As I mentioned above, I'm almost finished with the work on '%e' - it works allready for all floats, but the code needs some refactorisation, I did not check doubles and probably I have to do something for speedup; I think I can do the final tests next weekend.

Now I'm not sure if we want to do all four specifiers (%g should be easy once %f and %e works) separate or all in one PR. What do you prefere?

@ghost
Copy link
Author

ghost commented Dec 4, 2019

One more thing: %f currently does not pass one test, which is due to a different rounding tie. I meanwhile thought, that it might be easier to first use the old tie (so all tests pass) and then address this in a separate PR. In this case I should change it here too for consistency. What do you think?

@thewilsonator
Copy link
Contributor

and then address this in a separate PR.

Yes please.

In this case I should change it here too for consistency

I'm not sure I follow (I have a cold that the moment so its probably that), but do whatever you think is best.

@ghost
Copy link
Author

ghost commented Dec 4, 2019

I'm not sure I follow (I have a cold that the moment so its probably that), but do whatever you think is best.

Oh, my best wishes for a speedy recovery! :-)

@ghost
Copy link
Author

ghost commented Dec 4, 2019

I changed everything you requested locally. Before uploading it, I'll rerun the external tests to make sure I didn't break anything. This will take some time.

@thewilsonator
Copy link
Contributor

Ping me when you're good to go.

@ghost
Copy link
Author

ghost commented Dec 4, 2019

@thewilsonator All external tests passed. :-)

@wilzbach
Copy link
Contributor

wilzbach commented Dec 4, 2019

Concerning speed: dmd is a little bit slower with the new version, while ldc2 is slightly faster. See pdf-file for some diagrams.

FYI: You NEVER need to worry about DMD when doing perf analysis for druntime or phobos. DMD is absolutely slow and years ago it was decided that it's a massive waste of time to bother about it ;-)
Any serious application will use LDC anyhow (less bugs, more architectures, better perf, ...).

Copy link
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Copy link
Member

@CyberShadow CyberShadow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request introduced a performance regression for compilation time for a "Hello world" program:

https://perf.dlang.io/#program-hello-compile-callgrind-insns;;1575616914.215833;1575724556.863705

@@ -62,6 +62,7 @@ import std.exception;
import std.meta;
import std.range.primitives;
import std.traits;
import std.math : FloatingPointControl;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this top-level import is the cause.

Would it be possible to move it to a local import, by splitting the definition of the printFloat function into an eponymous template?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take care.

Probably I'll use a local enum for rounding modes instead of the solution with eponymous templates. That has the advantage, that I can add the fifth mode that IEEE allows for printing floats, which FloatingPointControl does not know about. (I plan a PR to make formatting floating point numbers pure by using this fifth mode for format and add a separate (nonpure) function, probably formatIEEE for rounding according to the processor state. I will need this enum there anyway.)

Shall I base this PR on stable, as it's some sort of regression?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the floating point rounding mode is explicitly allowed in pure code:

As a concession to practicality, a pure function can also:

  • read and write the floating point exception flags
  • read and write the floating point mode flags, as long as those flags are restored to their initial state upon function entry
  • perform impure operations in statements that are in a ConditionalStatement controlled by a DebugCondition.

dlang-bot added a commit that referenced this pull request Jan 12, 2020
Fix performance regression introduced by PR #7285.
merged-on-behalf-of: David Nadlinger <code@klickverbot.at>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants