Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that min <= max in clamp_finite #3699

Merged
merged 1 commit into from
Apr 2, 2024
Merged

Check that min <= max in clamp_finite #3699

merged 1 commit into from
Apr 2, 2024

Conversation

jedel1043
Copy link
Member

Fixes #3697.
We should assert that min <= max even if self is PositiveInfinity or NegativeInfinity.

@jedel1043 jedel1043 added the Internal Category for changelog label Feb 27, 2024
@jedel1043 jedel1043 added this to the v0.18.0 milestone Feb 27, 2024
@jedel1043 jedel1043 requested a review from a team February 27, 2024 14:33
@raskad
Copy link
Member

raskad commented Feb 27, 2024

I checked all calls to clamp_finite and they all have min = 0. So we could do something like this and avoid the panics:

    pub fn clamp_finite_positive(self, max: i64) -> i64 {
        match self {
            Self::Integer(i) if i < 0 => 0,
            Self::Integer(i) if i > max => max,
            Self::Integer(i) => i,
            Self::PositiveInfinity => max,
            Self::NegativeInfinity => 0,
        }
    }

Copy link

Test262 conformance changes

Test result main count PR count difference
Total 50,268 50,268 0
Passed 42,565 42,565 0
Ignored 1,570 1,570 0
Failed 6,133 6,133 0
Panics 0 0 0
Conformance 84.68% 84.68% 0.00%

@jedel1043
Copy link
Member Author

I think that method would be useful internally to skip some panics, but we still need to expose a clamp_finite method for users of the to_integer_or_infinity method.

@nekevss
Copy link
Member

nekevss commented Feb 27, 2024

I'd be fine with a clamp_finite_positive method for avoiding panics. I'm not entirely sold on whether it should be exposed as pub off the start.

@jedel1043 jedel1043 added the waiting-on-review Waiting on reviews from the maintainers label Mar 24, 2024
Copy link
Member

@nekevss nekevss left a comment

Choose a reason for hiding this comment

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

I'm fine with moving forward with this as is for now.

@nekevss nekevss requested a review from a team March 26, 2024 18:19
@raskad raskad added this pull request to the merge queue Apr 2, 2024
Merged via the queue into main with commit 5c20010 Apr 2, 2024
13 checks passed
@jedel1043 jedel1043 deleted the fix-3697 branch April 2, 2024 18:53
@jedel1043 jedel1043 removed the waiting-on-review Waiting on reviews from the maintainers label Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internal Category for changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible Incompleteness
3 participants