cmp/cmpopts/equate.go
func EquateApprox(fraction, margin float64) cmp.Option {
	if margin < 0 || fraction < 0 || math.IsNaN(margin) || math.IsNaN(fraction) {
		panic("margin or fraction must be a non-negative number")
	}
	a := approximator{fraction, margin}
	return cmp.Options{
		cmp.FilterValues(areRealF64s, cmp.Comparer(a.compareF64)),
		cmp.FilterValues(areRealF32s, cmp.Comparer(a.compareF32)),
	}
}
func EquateApprox(fraction, margin float64) cmp.Option {
	if margin < 0 || fraction < 0 || math.IsNaN(margin) || math.IsNaN(fraction) {
		panic("margin or fraction must be a non-negative number")
	}
	a := approximator{fraction, margin}
	return cmp.Options{
		cmp.FilterValues(areRealF64s, cmp.Comparer(a.compareF64)),
		cmp.FilterValues(areRealF32s, cmp.Comparer(a.compareF32)),
	}
}
func EquateApprox ( fraction , margin float64 ) cmp . Option { if margin < 0 || fraction < 0 || math . IsNaN ( margin ) || math . IsNaN ( fraction ) { panic ( " " ) } a := approximator { fraction , margin } return cmp . Options { cmp . FilterValues ( areRealF64s , cmp . Comparer ( a . compareF64 ) ) , cmp . FilterValues ( areRealF32s , cmp . Comparer ( a . compareF32 ) ) , } }
// EquateApprox returns a Comparer option that determines float32 or float64
// values to be equal if they are within a relative fraction or absolute margin.
// This option is not used when either x or y is NaN or infinite.
//
// The fraction determines that the difference of two values must be within the
// smaller fraction of the two values, while the margin determines that the two
// values must be within some absolute margin.
// To express only a fraction or only a margin, use 0 for the other parameter.
// The fraction and margin must be non-negative.
//
// The mathematical expression used is equivalent to:
//	|x-y| ≤ max(fraction*min(|x|, |y|), margin)
//
// EquateApprox can be used in conjunction with EquateNaNs.
EquateApprox returns a Comparer option that determines float32 or float64 values to be equal if they are within a relative fraction or absolute margin . This option is not used when either x or y is NaN or infinite . The fraction determines that the difference of two values must be within the smaller fraction of the two values while the margin determines that the two values must be within some absolute margin . To express only a fraction or only a margin use 0 for the other parameter . The fraction and margin must be non - negative . The mathematical expression used is equivalent to : |x - y| ≤ max ( fraction * min ( |x| |y| ) margin ) EquateApprox can be used in conjunction with EquateNaNs .