Skip to content

Commit

Permalink
fix printing thresholds when using perf-config
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Nov 7, 2024
1 parent 648aa08 commit dc11b6b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ func Int64E(raw interface{}) (int64, error) {
return int64(val), nil
case uint32:
return int64(val), nil
case float64:
return int64(val), nil
default:
num, err := strconv.ParseFloat(fmt.Sprintf("%v", val), 64)
num, err := Float64E(raw)
if err != nil {
return 0, fmt.Errorf("cannot parse int64 value from %v (%T)", raw, raw)
}
Expand All @@ -89,12 +91,12 @@ func UInt64E(raw interface{}) (uint64, error) {
case uint64:
return val, nil
default:
num, err := strconv.ParseUint(fmt.Sprintf("%v", val), 10, 64)
num, err := Float64E(raw)
if err != nil {
return 0, fmt.Errorf("cannot parse uint64 value from %v (%T)", raw, raw)
}

return num, nil
return uint64(num), nil
}
}

Expand Down Expand Up @@ -305,7 +307,7 @@ func Num2StringE(raw interface{}) (string, error) {
case int64:
return fmt.Sprintf("%d", num), nil
default:
fNum, err := strconv.ParseFloat(fmt.Sprintf("%v", raw), 64)
fNum, err := Float64E(raw)
if err != nil {
return "", fmt.Errorf("cannot convert %v (%T) into string", raw, raw)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/convert/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func TestConvertFloat64E(t *testing.T) {
{"1.5", 1.5, false},
{"1", 1, false},
{"1e7", 1e7, false},
{"1.4847215616e+10", 14847215616, false},
{"1.4847215616e+8", 148472156.16, false},
{"", 0, true},
{"abc", 0, true},
}
Expand Down

0 comments on commit dc11b6b

Please sign in to comment.