MCPcopy Index your code
hub / github.com/expr-lang/expr / calcRelativeError

Function calcRelativeError

internal/testify/assert/assertions.go:1461–1481  ·  view source on GitHub ↗
(expected, actual interface{})

Source from the content-addressed store, hash-verified

1459}
1460
1461func calcRelativeError(expected, actual interface{}) (float64, error) {
1462 af, aok := toFloat(expected)
1463 bf, bok := toFloat(actual)
1464 if !aok || !bok {
1465 return 0, fmt.Errorf("Parameters must be numerical")
1466 }
1467 if math.IsNaN(af) && math.IsNaN(bf) {
1468 return 0, nil
1469 }
1470 if math.IsNaN(af) {
1471 return 0, errors.New("expected value must not be NaN")
1472 }
1473 if af == 0 {
1474 return 0, fmt.Errorf("expected value must have a value other than zero to calculate the relative error")
1475 }
1476 if math.IsNaN(bf) {
1477 return 0, errors.New("actual value must not be NaN")
1478 }
1479
1480 return math.Abs(af-bf) / math.Abs(af), nil
1481}
1482
1483// InEpsilon asserts that expected and actual have a relative error less than epsilon
1484func InEpsilon(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool {

Callers 1

InEpsilonFunction · 0.85

Calls 2

toFloatFunction · 0.70
ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…