Skip to content

std.format: Add %g (step 7): Change calculating the split#7836

Merged
dlang-bot merged 1 commit intodlang:masterfrom
berni44:format_add_g_variant
Mar 12, 2021
Merged

std.format: Add %g (step 7): Change calculating the split#7836
dlang-bot merged 1 commit intodlang:masterfrom
berni44:format_add_g_variant

Conversation

@berni44
Copy link
Contributor

@berni44 berni44 commented Mar 10, 2021

As I already wrote in #7810, I'm rather reluctant to use the functions simulating floating point math. So this PR can be thought of as being a questioning PR, asking, which variation we should use.

Some reasons, why I'd like to remove the simulating functions:

  • I compared the results of both variations with the output of glibc's snprintf: All three variations differ and I'm convinced that different implementations of snprintf will differ too. It might even happen, that the result might differ depending on the compiler and optimization turned on or not.
  • I fear, that the simulating functions will cause problems with the implementation of reals. It might even be the case, that real==double doesn't work. I've got a bad feeling about this, but can't really break this down to anything concrete. It's just my programmers instinct.
  • Ugly code (calling less() instead of < and so on). Does not feel right.
  • The way, D implements floating point math implies a certain uncertainity of the outcome of floating point calculations, by only specifying a minimum precision and using reals internally for calculation. Taking this into account, I have to conclude, that it was intentional by the language designers, that there is some uncertainity left, whenever floating point numbers are involved.
  • Although I do not completely understand the reason for this change, it works with fabs too, while the simulating functions do not do so (a cast would probably be needed there).

Finally, I do not know exactly, how large the gap of uncertainity is. I tried to use just 3 nextUps. Let's see, if the tests still work on all computers, or if I have to widen the gap...

@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

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

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

dub run digger -- build "master + phobos#7836"

@dlang-bot dlang-bot merged commit c6efda9 into dlang:master Mar 12, 2021
@berni44 berni44 deleted the format_add_g_variant branch April 28, 2021 17:39
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.

3 participants