Round sqrt correctly in the current rounding mode - #1463
Merged
Merged
Conversation
- IEEE 754-2019 4.3 and 5.4.1: sqrt gives the infinitely precise root rounded in the current mode. The 32 and 64 bit kernels truncated the integer root, an odd exponent multiplied the root by a rounded sqrt(10) for the three sizes, and no kernel read the mode. - For an odd exponent the three kernels take the root of 10 * gx, so the result is rounded once. The estimate is scaled by an integer sqrt(10), and the Newton steps correct it. The multiply by sqrt10_v goes away. - A new helper reads the mode, and the final step of each kernel keeps the floor, steps up on a remainder, or steps up past the half point. - The step down to the floor is a loop. One Newton step can land two above the floor when the estimate is off and the root ends near .999. - An odd power of ten takes the kernel path too. The old fast path gave sqrt(0.1) one step low, and test_sqrt.cpp expected that value. - A new test compares sqrt against the floor and the ceiling of the root for the six types in the five modes, with a sibling under the compile-time upward mode. Fixes boostorg#1462
ibmibmibm
marked this pull request as ready for review
September 21, 2026 13:03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
rounded in the current mode. The 32 and 64 bit kernels truncated the
integer root, an odd exponent multiplied the root by a rounded sqrt(10)
for the three sizes, and no kernel read the mode.
result is rounded once. The estimate is scaled by an integer sqrt(10),
and the Newton steps correct it. The multiply by sqrt10_v goes away.
the floor, steps up on a remainder, or steps up past the half point.
above the floor when the estimate is off and the root ends near .999.
sqrt(0.1) one step low, and test_sqrt.cpp expected that value.
for the six types in the five modes, with a sibling under the
compile-time upward mode.
Fixes #1462