aboutsummaryrefslogtreecommitdiff
path: root/lib/std/math.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-05-02 01:53:24 -0400
committerAndrew Kelley <andrew@ziglang.org>2020-05-02 01:53:24 -0400
commitbeebcbb677350b86c9f36a850a8b8853b7a71769 (patch)
treecc9c09cecdc0c702d1f1f34ae87967dcc98c4089 /lib/std/math.zig
parent43f7856bac5fd1a93970d7cebd20289de2367691 (diff)
parent3dbe02e2d8cda1fe0072e71ae7630170c270419e (diff)
downloadzig-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.zig37
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.