From 6b0f7de247f3c12281f47f38738e93651d6bf51b Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 28 Apr 2020 21:04:18 -0400 Subject: ZIR: add cmp and condbr instructions --- lib/std/math.zig | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'lib/std/math.zig') 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. -- cgit v1.2.3