From 13d5d2e7dc255046a38076a62544439f7d32b11d Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Wed, 21 Jun 2023 19:38:48 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=AF=94=E8=BE=83=E8=BE=85?= =?UTF-8?q?=E5=8A=A9=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/maths/compare.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 utils/maths/compare.go diff --git a/utils/maths/compare.go b/utils/maths/compare.go new file mode 100644 index 0000000..b7d7c85 --- /dev/null +++ b/utils/maths/compare.go @@ -0,0 +1,31 @@ +package maths + +import "github.com/kercylan98/minotaur/utils/generic" + +const ( + CompareGreaterThan CompareExpression = 1 // 大于 + CompareGreaterThanOrEqual CompareExpression = 2 // 大于等于 + CompareLessThan CompareExpression = 3 // 小于 + CompareLessThanOrEqual CompareExpression = 4 // 小于等于 + CompareEqual CompareExpression = 5 // 等于 +) + +// CompareExpression 比较表达式 +type CompareExpression int + +// Compare 根据特定表达式比较两个值 +func Compare[V generic.Ordered](a V, expression CompareExpression, b V) bool { + switch expression { + case CompareGreaterThan: + return a > b + case CompareGreaterThanOrEqual: + return a >= b + case CompareLessThan: + return a < b + case CompareLessThanOrEqual: + return a <= b + case CompareEqual: + return a == b + } + panic("unknown expression") +}