MCPcopy Create free account
hub / github.com/expr-lang/expr / Abs

Function Abs

builtin/lib.go:60–116  ·  view source on GitHub ↗
(x any)

Source from the content-addressed store, hash-verified

58}
59
60func Abs(x any) any {
61 switch x := x.(type) {
62 case float32:
63 if x < 0 {
64 return -x
65 } else {
66 return x
67 }
68 case float64:
69 if x < 0 {
70 return -x
71 } else {
72 return x
73 }
74 case int:
75 if x < 0 {
76 return -x
77 } else {
78 return x
79 }
80 case int8:
81 if x < 0 {
82 return -x
83 } else {
84 return x
85 }
86 case int16:
87 if x < 0 {
88 return -x
89 } else {
90 return x
91 }
92 case int32:
93 if x < 0 {
94 return -x
95 } else {
96 return x
97 }
98 case int64:
99 if x < 0 {
100 return -x
101 } else {
102 return x
103 }
104 case uint:
105 return x
106 case uint8:
107 return x
108 case uint16:
109 return x
110 case uint32:
111 return x
112 case uint64:
113 return x
114 }
115 panic(fmt.Sprintf("invalid argument for abs (type %T)", x))
116}
117

Callers

nothing calls this directly

Calls 1

SprintfMethod · 0.80

Tested by

no test coverage detected