diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-05-02 01:53:24 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-05-02 01:53:24 -0400 |
| commit | beebcbb677350b86c9f36a850a8b8853b7a71769 (patch) | |
| tree | cc9c09cecdc0c702d1f1f34ae87967dcc98c4089 /lib/std/math.zig | |
| parent | 43f7856bac5fd1a93970d7cebd20289de2367691 (diff) | |
| parent | 3dbe02e2d8cda1fe0072e71ae7630170c270419e (diff) | |
| download | zig-beebcbb677350b86c9f36a850a8b8853b7a71769.tar.gz zig-beebcbb677350b86c9f36a850a8b8853b7a71769.zip | |
Merge remote-tracking branch 'origin/master' into FireFox317-windows-evented-io
Diffstat (limited to 'lib/std/math.zig')
| -rw-r--r-- | lib/std/math.zig | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/std/math.zig b/lib/std/math.zig index 8c07f3c8be..5cf6d40d8a 100644 --- a/lib/std/math.zig +++ b/lib/std/math.zig @@ -986,6 +986,43 @@ pub const Order = enum { /// Greater than (`>`) gt, + + pub fn invert(self: Order) Order { + return switch (self) { + .lt => .gt, + .eq => .eq, + .gt => .gt, + }; + } + + pub fn compare(self: Order, op: CompareOperator) bool { + return switch (self) { + .lt => switch (op) { + .lt => true, + .lte => true, + .eq => false, + .gte => false, + .gt => false, + .neq => true, + }, + .eq => switch (op) { + .lt => false, + .lte => true, + .eq => true, + .gte => true, + .gt => false, + .neq => false, + }, + .gt => switch (op) { + .lt => false, + .lte => false, + .eq => false, + .gte => true, + .gt => true, + .neq => true, + }, + }; + } }; /// Given two numbers, this function returns the order they are with respect to each other. |
