Skip to content

Confusing difference between float and integer in min and max #247

Closed
@lukaslihotzki

Description

@lukaslihotzki

I tried this code:

let a = u32x4::from_array([0, 1, 0, 1]);
let b = u32x4::from_array([1, 0, 1, 0]);
print!("{:x?} ", a.min(b));

let a = f32x4::from_array([0., 1., 0., 1.]);
let b = f32x4::from_array([1., 0., 1., 0.]);
print!("{:x?}\n", a.min(b));

I expected to see this happen: [0, 0, 0, 0] [0.0, 0.0, 0.0, 0.0].
[0, 1, 0, 1] [0.0, 1.0, 0.0, 1.0] would be a little surprising, because that isn't commonly available as native SIMD instruction.

Instead, this happened: [0, 1, 0, 1] [0.0, 0.0, 0.0, 0.0]

This is inconsistent. I expected either min or lanes_min (like in lanes_eq) to get the minimum for each lane.

Also, when you search min( in https://rust-lang.github.io/portable-simd/core_simd/simd/struct.Simd.html#method.min-1, where it says "Returns the minimum of each lane.", you have to scroll up quite a bit to see it is for floats only and the documentation of min and max for integers is very generic, doesn't explicitly mention that this isn't per lane.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions