Repository navigation
Fix nearbyint and rint in directed rounding modes - #1425
Open
monishpeddapally wants to merge 1 commit into
Open
monishpeddapally wants to merge 1 commit into
monishpeddapally wants to merge 1 commit into
Conversation
The common kernel rounds the absolute input before restoring its sign, which reverses directed rounding for negative values. Keep the input signed during addition and subtraction, and copy its sign to the result to preserve signed zero. Use the current rounding direction in SSE4.1, AVX and AVX-512 instructions instead of selecting round-to-nearest. Add mixed-lane regressions for float and double across the four standard rounding modes. Fixes xtensor-stack#1424 Signed-off-by: Monish Peddapally <93381641+monishpeddapally@users.noreply.github.com>
Contributor
|
we should test, nan, inf, and numbers largest than the largest representable integer since we are at it. Probably we should also fix the use of _MM_FROUND_CUR_DIRECTION I think we are suppressing exceptions there. |
DiamonDinoia
requested changes
Oct 14, 2026
DiamonDinoia
left a comment
Contributor
There was a problem hiding this comment.
Please, double check the code as I think there is some AI usage in it that might have changed things that should not be changed.
| return s ^ select(v < t2n, d, v); | ||
| batch_type signed_t2n = t2n | s; | ||
| batch_type d0 = self + signed_t2n; | ||
| detail::reassociation_barrier(d0, "prevent collapsing (x + c) - c back to x"); |
Contributor
There was a problem hiding this comment.
where is c? why did you change the variable names in the string?
This branch has not been deployed
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.
Fixes #1424.
Batch
nearbyintandrintcurrently return incorrect values under directed rounding. The common kernel rounds magnitudes before restoring the sign, which reverses the direction for negative inputs. SSE4.1, AVX and AVX-512 explicitly select round-to-nearest.Keep signed inputs during the common kernel's rounding arithmetic, preserve signed zero, and use the current rounding direction in the x86 instructions. The regression checks mixed positive and negative lanes, halfway cases, integral values and signed zero for float and double. It restores the original rounding mode and skips modes unsupported by the platform.
Validation on macOS with Apple Clang 21:
git diff --checkpass. The local inline-specifier script could not run becauseclang-queryis unavailable.This change addresses returned values. Floating-point exception-flag behavior is outside its scope.