Scientific implements formatStringInterpolatorV2.Scientific.
(precision int)
| 275 | |
| 276 | // Scientific implements formatStringInterpolatorV2.Scientific. |
| 277 | func (c *stringFormatterV2) Scientific(precision int) func(ref.Val) (string, error) { |
| 278 | return func(arg ref.Val) (string, error) { |
| 279 | fmtStr := fmt.Sprintf("%%1.%de", precision) |
| 280 | switch arg.Type() { |
| 281 | case types.IntType: |
| 282 | argInt, ok := arg.Value().(int64) |
| 283 | if !ok { |
| 284 | return "", fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.IntType) |
| 285 | } |
| 286 | return fmt.Sprintf(fmtStr, float64(argInt)), nil |
| 287 | case types.UintType: |
| 288 | argUint, ok := arg.Value().(uint64) |
| 289 | if !ok { |
| 290 | return "", fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.UintType) |
| 291 | } |
| 292 | return fmt.Sprintf(fmtStr, float64(argUint)), nil |
| 293 | case types.DoubleType: |
| 294 | argDbl, ok := arg.Value().(float64) |
| 295 | if !ok { |
| 296 | return "", fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.DoubleType) |
| 297 | } |
| 298 | if math.IsNaN(argDbl) { |
| 299 | return "NaN", nil |
| 300 | } |
| 301 | if math.IsInf(argDbl, -1) { |
| 302 | return "-Infinity", nil |
| 303 | } |
| 304 | if math.IsInf(argDbl, 1) { |
| 305 | return "Infinity", nil |
| 306 | } |
| 307 | return fmt.Sprintf(fmtStr, argDbl), nil |
| 308 | default: |
| 309 | return "", scientificFormatErrorV2(runtimeID, arg.Type().TypeName()) |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | // Binary implements formatStringInterpolatorV2.Binary. |
| 315 | func (c *stringFormatterV2) Binary(arg ref.Val) (string, error) { |
nothing calls this directly
no test coverage detected