1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-13 01:02:28 +08:00

feat: InDelta (#127)

This commit is contained in:
warpmatrix
2023-08-15 09:53:16 +08:00
committed by GitHub
parent b5f86a488c
commit c5a5a07462
4 changed files with 97 additions and 0 deletions

View File

@@ -10,6 +10,8 @@ import (
"time"
"github.com/duke-git/lancet/v2/convertor"
"github.com/duke-git/lancet/v2/mathutil"
"golang.org/x/exp/constraints"
)
// operator type
@@ -62,3 +64,8 @@ func LessOrEqual(left, right any) bool {
func GreaterOrEqual(left, right any) bool {
return compareValue(greaterOrEqual, left, right)
}
// InDelta checks if two values are equal or not within a delta.
func InDelta[T constraints.Integer | constraints.Float](left, right T, delta float64) bool {
return float64(mathutil.Abs(left-right)) <= delta
}