mirror of
https://github.com/minio/minio.git
synced 2025-11-20 18:06:10 -05:00
add ruleguard support, fix all the reported issues (#10335)
This commit is contained in:
@@ -246,6 +246,8 @@ func (e *ListExpr) evalNode(r Record) (*Value, error) {
|
||||
return FromArray(res), nil
|
||||
}
|
||||
|
||||
const floatCmpTolerance = 0.000001
|
||||
|
||||
func (e *In) evalInNode(r Record, lhs *Value) (*Value, error) {
|
||||
// Compare two values in terms of in-ness.
|
||||
var cmp func(a, b Value) bool
|
||||
@@ -275,7 +277,8 @@ func (e *In) evalInNode(r Record, lhs *Value) (*Value, error) {
|
||||
aF, aOK := a.ToFloat()
|
||||
bF, bOK := b.ToFloat()
|
||||
|
||||
return aOK && bOK && aF == bF
|
||||
diff := math.Abs(aF - bF)
|
||||
return aOK && bOK && diff < floatCmpTolerance
|
||||
}
|
||||
|
||||
var rhs Value
|
||||
|
||||
@@ -785,6 +785,7 @@ func intCompare(op string, left, right int64) bool {
|
||||
}
|
||||
|
||||
func floatCompare(op string, left, right float64) bool {
|
||||
diff := math.Abs(left - right)
|
||||
switch op {
|
||||
case opLt:
|
||||
return left < right
|
||||
@@ -795,9 +796,9 @@ func floatCompare(op string, left, right float64) bool {
|
||||
case opGte:
|
||||
return left >= right
|
||||
case opEq:
|
||||
return left == right
|
||||
return diff < floatCmpTolerance
|
||||
case opIneq:
|
||||
return left != right
|
||||
return diff > floatCmpTolerance
|
||||
}
|
||||
// This case does not happen
|
||||
return false
|
||||
|
||||
@@ -559,7 +559,8 @@ func TestValue_bytesToFloat(t *testing.T) {
|
||||
value: tt.fields.value,
|
||||
}
|
||||
got, got1 := v.bytesToFloat()
|
||||
if got != tt.want {
|
||||
diff := math.Abs(got - tt.want)
|
||||
if diff > floatCmpTolerance {
|
||||
t.Errorf("bytesToFloat() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
if got1 != tt.wantOK {
|
||||
|
||||
Reference in New Issue
Block a user