std: Rework std.math.order and std.math.Order#23387
std: Rework std.math.order and std.math.Order#23387SeanTUT wants to merge 20 commits intoziglang:masterfrom
std.math.order and std.math.Order#23387Conversation
- Moved implementations of `std.math.order` and `std.math.Order` into their own file (lib/std/math/order.zig) - Floats use total ordering, eliminating the possibility of reaching unreachable code in `std.math.order` - `.lt`, `.eq`, and `.gt` now have vales of `-1`, `0`, and `1` respectively, allowing for some optimizations in ordering integers inverting orderings - `std.mem.order` now utilizes `std.math.Order.differ` instead of manually implementing the functionality - Modified up some existing tests to use `std.testing.expectEqual` instead of `std.testing.expect` when appropriate
…nto order-patch
In math/order.zig, cast the results of the comparison to i8 before subtracting. This sidesteps the discovered bug.
This test was intended for investigating a compiler bug which will be looked into seperately
Previously this would result in -0, which resulted in compiler bugs with
comptime arithmetic (affecting switch, @enumFromInt, and more).
With this bug fixed, several improvements in std.math.order became
possible, including branchless std.math.order and optimized
std.math.Order.{invert, compare}
Integer literals are now used again instead of runtime integer constants
Fixes comptime comparison of `0.0` and `-0.0` `
|
As is indicated by the repeated failure of tests, this change is becoming much more involved than it seemed at a glance. I expect to have this finished in a few days. |
|
A follow-up change might be to edit |
The possibolity of negation flipping the signal nan bit is now taken into account
…nto order-patch
Forgoes the branchless implementation in stage2_riscv64 entirely to enable support
|
Now that this is (finally, haha) done and in working order, I would like to hear any opinions on the breakage made by total ordering. This only changes how zeros of different signs are ordered, so it is a niche case, but it could be worth considering. Despite that, I think total ordering is the sanest way to go about this; it is a part of the IEEE 754 standard and covers all edge cases. If we want to eliminate breakage, we could split the current |
Revival of #23291
Orderare now explicitly specifiedlt = -1eq = 0gt = 1Order.invertandOrder.comparestd.math.orderis now implemented branchlessly, for both floats and integersstd.math.orderfor floats now uses IEEE total ordering{-nan, -inf, -real, -0, +0, +real, inf, nan}This is not a breaking change, as it only affects cases which were previously illegalstd.math.orderusers:0.0and-0.0and no longer treated as equal, in contrast to regular IEEE comparisons, where0.0 == -0.0std.math.big.int.subCarryreturning-0when subtracting0 - 0. This had in turn caused some compiler bugs with comptime arithmetic, which made themselves apparent while working on this