MCPcopy Create free account
hub / github.com/crossplane-contrib/function-patch-and-transform / ResolveMath

Function ResolveMath

transforms.go:103–120  ·  view source on GitHub ↗

ResolveMath resolves a Math transform.

(t *v1beta1.MathTransform, input any)

Source from the content-addressed store, hash-verified

101
102// ResolveMath resolves a Math transform.
103func ResolveMath(t *v1beta1.MathTransform, input any) (any, error) {
104 if err := ValidateMathTransform(t); err != nil {
105 return nil, err
106 }
107 switch input.(type) {
108 case int, int64, float64:
109 default:
110 return nil, errors.Errorf(errFmtMathInputNonNumber, input)
111 }
112 switch t.Type {
113 case v1beta1.MathTransformTypeMultiply:
114 return resolveMathMultiply(t, input)
115 case v1beta1.MathTransformTypeClampMin, v1beta1.MathTransformTypeClampMax:
116 return resolveMathClamp(t, input)
117 default:
118 return nil, errors.Errorf(errMathTransformTypeFailed, string(t.Type))
119 }
120}
121
122// resolveMathMultiply resolves a multiply transform, returning an error if the
123// input is not a number. If the input is a float, the result will be a float64, otherwise

Callers 2

ResolveFunction · 0.85
TestMathResolveFunction · 0.85

Calls 3

ValidateMathTransformFunction · 0.85
resolveMathMultiplyFunction · 0.85
resolveMathClampFunction · 0.85

Tested by 1

TestMathResolveFunction · 0.68