MCPcopy Create free account
hub / github.com/cel-expr/cel-go / Fixed

Method Fixed

ext/formatting_v2.go:239–274  ·  view source on GitHub ↗

Fixed implements formatStringInterpolatorV2.Fixed.

(precision int)

Source from the content-addressed store, hash-verified

237
238// Fixed implements formatStringInterpolatorV2.Fixed.
239func (c *stringFormatterV2) Fixed(precision int) func(ref.Val) (string, error) {
240 return func(arg ref.Val) (string, error) {
241 fmtStr := fmt.Sprintf("%%.%df", precision)
242 switch arg.Type() {
243 case types.IntType:
244 argInt, ok := arg.Value().(int64)
245 if !ok {
246 return "", fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.IntType)
247 }
248 return fmt.Sprintf(fmtStr, float64(argInt)), nil
249 case types.UintType:
250 argUint, ok := arg.Value().(uint64)
251 if !ok {
252 return "", fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.UintType)
253 }
254 return fmt.Sprintf(fmtStr, float64(argUint)), nil
255 case types.DoubleType:
256 argDbl, ok := arg.Value().(float64)
257 if !ok {
258 return "", fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.DoubleType)
259 }
260 if math.IsNaN(argDbl) {
261 return "NaN", nil
262 }
263 if math.IsInf(argDbl, -1) {
264 return "-Infinity", nil
265 }
266 if math.IsInf(argDbl, 1) {
267 return "Infinity", nil
268 }
269 return fmt.Sprintf(fmtStr, argDbl), nil
270 default:
271 return "", fixedPointFormatErrorV2(runtimeID, arg.Type().TypeName())
272 }
273 }
274}
275
276// Scientific implements formatStringInterpolatorV2.Scientific.
277func (c *stringFormatterV2) Scientific(precision int) func(ref.Val) (string, error) {

Callers

nothing calls this directly

Calls 4

fixedPointFormatErrorV2Function · 0.85
TypeMethod · 0.65
ValueMethod · 0.65
TypeNameMethod · 0.65

Tested by

no test coverage detected