Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

core.math: Add templated toPrec. #2864

Merged
merged 1 commit into from
Dec 11, 2019
Merged

core.math: Add templated toPrec. #2864

merged 1 commit into from
Dec 11, 2019

Conversation

ibuclaw
Copy link
Member

@ibuclaw ibuclaw commented Dec 10, 2019

Some floating point algorithms, such as Kahan-Babuska-Neumaier Summation,
require rounding to specific precisions. Rounding to precision after
every operation, however, loses overall precision in the general case
and is a runtime performance problem.

Adding these functions guarantee the rounding at required points in the
code, and document where in the algorithm the requirement exists.

Rebase of #1941.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @ibuclaw!

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 fetch digger
dub run digger -- build "master + druntime#2864"

* f in precision of type `T`
*/
@safe pure nothrow
T toPrec(T:float)(float f) { pragma(inline, false); return f; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Why pragma(inline, false);?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would assume just in case the inliner removes the call before builtins handler is given a chance to expand it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm worried about performance, but I suppose if this is a CTFE only intrinsic then there is no problem.

Some floating point algorithms, such as Kahan-Babuska-Neumaier Summation,
require rounding to specific precisions. Rounding to precision after
every operation, however, loses overall precision in the general case
and is a runtime performance problem.

Adding these functions guarantee the rounding at required points in the
code, and document where in the algorithm the requirement exists.
@ibuclaw
Copy link
Member Author

ibuclaw commented Dec 11, 2019

Disabling problematic tests until compiler support has been added.

@dlang-bot dlang-bot merged commit 5b56156 into dlang:master Dec 11, 2019
@ibuclaw ibuclaw deleted the to_prec branch December 11, 2019 07:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants