Skip to content

Fix std.mem.orderZ for types for which 0 is not the least element#22618

Open
Fri3dNstuff wants to merge 1 commit intoziglang:masterfrom
Fri3dNstuff:std.mem.orderZ
Open

Fix std.mem.orderZ for types for which 0 is not the least element#22618
Fri3dNstuff wants to merge 1 commit intoziglang:masterfrom
Fri3dNstuff:std.mem.orderZ

Conversation

@Fri3dNstuff
Copy link
Contributor

This PR fixes an oversight in std.mem.orderZ that caused the function to sometimes produce wrong results for slices of signed integers and floats.

Added test case:

try testing.expect(orderZ(i8, &.{ -1, -2 }, &.{ -1, -2, -3 }) == .lt);

@Fri3dNstuff Fri3dNstuff changed the title Fix std.mem.orderZ for types for which 0 is not the least number Fix std.mem.orderZ for types for which 0 is not the least element Jan 26, 2025
@Fri3dNstuff
Copy link
Contributor Author

There's still the issue of floating point numbers to be discussed: IEEE-754 (in its infinite wisdom...) declares 0.0 == -0.0, meaning the following will return .eq:

std.mem.orderZ(f32, &.{ 1.0, 2.0 }, &.{ 1.0, 2.0, -0.0 })

Should this be addressed? If so, other functions operating on sentinel-terminated values (std.mem.len, etc) ought to be looked at too.

@andrewrk andrewrk self-requested a review January 30, 2025 06:02
IOKG04 added a commit to IOKG04/zig that referenced this pull request Aug 3, 2025
closes ziglang#22618 (from where i stole the code)

i don't think this syntax will work with pull requests,
but i can try at least :3
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

Successfully merging this pull request may close these issues.

1 participant