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

Inconsistent behaviour of SimdPartialOrd::simd_min and simd_max when values are not comparable #51

Open
arscisca opened this issue Dec 15, 2023 · 1 comment

Comments

@arscisca
Copy link

arscisca commented Dec 15, 2023

When values are not comparable, these methods always return the second value.

An example of this is calling simd_min on a valid f32 and f32::NAN:

let number = 1.0f32;
let nan = f32::NAN;
println!("{}", number.simd_min(nan)); // Prints "NaN"
println!("{}", nan.simd_min(number)); // Prints "1"

This happens because the current implementation of simd_min is the following:

fn simd_min(self, other: Self) -> Self {
    if self <= other {
        self
    } else {
        other
    }
}

and a <= (or any syntax-sugared comparison in general) between two instances of a PartialOrd type where a.partial_ord(&b) returns None is evaluated to false.

@arscisca
Copy link
Author

On a side note, all the other comparison methods under SimdPartialOrd will return a bool regardless of whether the values are actually comparable or not. I imagine this is either SIMD requirement or a convenience choice, but at this point isn't the trait behaving more like a SimdOrd which is implemented for PartialOrd types like f32 and f64 for convenience?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant