go-hep.org/x/hep@v0.38.1/groot/cmd/root-gen-rfunc/testdata/math_abs_golden.txt (about) 1 // MyAbs implements rfunc.Formula 2 type MyAbs struct { 3 rvars []string 4 arg0 *float64 5 fct func(arg00 float64) float64 6 } 7 8 // NewMyAbs return a new formula, from the provided function. 9 func NewMyAbs(rvars []string, fct func(arg00 float64) float64) *MyAbs { 10 return &MyAbs{ 11 rvars: rvars, 12 fct: fct, 13 } 14 } 15 16 17 // RVars implements rfunc.Formula 18 func (f *MyAbs) RVars() []string { return f.rvars } 19 20 21 // Bind implements rfunc.Formula 22 func (f *MyAbs) Bind(args []any) error { 23 if got, want := len(args), 1; got != want { 24 return fmt.Errorf( 25 "rfunc: invalid number of bind arguments (got=%d, want=%d)", 26 got, want, 27 ) 28 } 29 { 30 ptr, ok := args[0].(*float64) 31 if !ok { 32 return fmt.Errorf( 33 "rfunc: argument type 0 (name=%s) mismatch: got=%T, want=*float64", 34 f.rvars[0], args[0], 35 ) 36 } 37 f.arg0 = ptr 38 } 39 return nil 40 } 41 42 // Func implements rfunc.Formula 43 func (f *MyAbs) Func() any { 44 return func() float64 { 45 return f.fct( 46 *f.arg0, 47 ) 48 } 49 } 50 51 var ( 52 _ rfunc.Formula = (*MyAbs)(nil) 53 )