Skip to content

Commit

Permalink
Adjust cost factor clamping
Browse files Browse the repository at this point in the history
  • Loading branch information
TristonianJones committed Oct 27, 2023
1 parent e053062 commit 7d5fa42
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions checker/cost.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func addUint64NoOverflow(x, y uint64) uint64 {
// multiplyUint64NoOverflow multiplies non-negative ints. If the result is exceeds math.MaxUint64, math.MaxUint64
// is returned.
func multiplyUint64NoOverflow(x, y uint64) uint64 {
if x > 0 && y > 0 && x > math.MaxUint64/y {
if y != 0 && x > math.MaxUint64/y {
return math.MaxUint64
}
return x * y
Expand All @@ -238,7 +238,11 @@ func multiplyByCostFactor(x uint64, y float64) uint64 {
if xFloat > 0 && y > 0 && xFloat > math.MaxUint64/y {
return math.MaxUint64
}
return uint64(math.Ceil(xFloat * y))
ceil := math.Ceil(xFloat * y)
if ceil >= doubleTwoTo64 {
return math.MaxUint64
}
return uint64(ceil)
}

var (
Expand Down Expand Up @@ -692,3 +696,7 @@ func isScalar(t *types.Type) bool {
}
return false
}

var (
doubleTwoTo64 = math.Ldexp(1.0, 64)
)

0 comments on commit 7d5fa42

Please sign in to comment.