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

Method Scientific

ext/formatting.go:314–342  ·  view source on GitHub ↗

Scientific implements formatStringInterpolator.Scientific.

(precision *int)

Source from the content-addressed store, hash-verified

312
313// Scientific implements formatStringInterpolator.Scientific.
314func (c *stringFormatter) Scientific(precision *int) func(ref.Val, string) (string, error) {
315 if precision == nil {
316 precision = new(int)
317 *precision = defaultPrecision
318 }
319 return func(arg ref.Val, locale string) (string, error) {
320 strException := false
321 if arg.Type() == types.StringType {
322 argStr := arg.Value().(string)
323 if argStr == "NaN" || argStr == "Infinity" || argStr == "-Infinity" {
324 strException = true
325 }
326 }
327 if arg.Type() != types.DoubleType && !strException {
328 return "", scientificFormatError(runtimeID, arg.Type().TypeName())
329 }
330 argFloatVal := arg.ConvertToType(types.DoubleType)
331 argFloat, ok := argFloatVal.Value().(float64)
332 if !ok {
333 return "", fmt.Errorf("could not convert \"%v\" to float64", argFloatVal.Value())
334 }
335 matchedLocale, err := matchLanguage(locale)
336 if err != nil {
337 return "", fmt.Errorf("error matching locale: %w", err)
338 }
339 fmtStr := fmt.Sprintf("%%%de", *precision)
340 return message.NewPrinter(matchedLocale).Sprintf(fmtStr, argFloat), nil
341 }
342}
343
344// Binary implements formatStringInterpolator.Binary.
345func (c *stringFormatter) Binary(arg ref.Val, locale string) (string, error) {

Callers

nothing calls this directly

Calls 6

scientificFormatErrorFunction · 0.85
matchLanguageFunction · 0.85
TypeMethod · 0.65
ValueMethod · 0.65
TypeNameMethod · 0.65
ConvertToTypeMethod · 0.65

Tested by

no test coverage detected