Fix int(QuadPrecision) for NaN, Inf, and out-of-int64 values#104
Open
SwayamInSync wants to merge 2 commits into
Open
Fix int(QuadPrecision) for NaN, Inf, and out-of-int64 values#104SwayamInSync wants to merge 2 commits into
int(QuadPrecision) for NaN, Inf, and out-of-int64 values#104SwayamInSync wants to merge 2 commits into
Conversation
int(QuadPrecision) for NaN, Inf, and out-of-int64 values
ngoldbaum
reviewed
May 19, 2026
| // Route the longdouble backend through quad as as_integer_ratio does; | ||
| // the prior `(long long)longdouble_value` cast also saturated/UBed on | ||
| // NaN/Inf/out-of-range. | ||
| value = Sleef_cast_from_doubleq1((double)self->value.longdouble_value); |
Member
There was a problem hiding this comment.
Both this and the similar cast alluded to in the comment will lose precision on any platform with extended precision native long double.
Instead of doing this, you should write a utility function that checks for NaN and inf with std::isnan and std::isinf, which do support extended precision long double natively and then write the value to a string buffer, which you can parse however you need it.
ngoldbaum
reviewed
May 19, 2026
| assert int(QuadPrecision(str(n))) == n | ||
|
|
||
| @pytest.mark.parametrize("exponent", [40, 60, 80, 100]) | ||
| def test_int_powers_of_two_far_above_int64(self, exponent): |
Member
There was a problem hiding this comment.
This and many other tests in this file aren't parametrized by the backend, which leads to missing the issue I pointed out above.
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.
closes #97
AI Disclosure:
Claude wrote the test cases