chore: refactor to use builtin max/min (#15817)

* passed the tests with inbuilt max func

* tested min changes

* fix bazel files

* added changelog
This commit is contained in:
Sahil Sojitra
2025-10-08 00:32:47 +05:30
committed by GitHub
parent 537f3cb863
commit 9805e90d73
26 changed files with 26 additions and 139 deletions

View File

@@ -117,30 +117,6 @@ func PowerOf2(n uint64) uint64 {
return 1 << n
}
// Max returns the larger integer of the two
// given ones.This is used over the Max function
// in the standard math library because that max function
// has to check for some special floating point cases
// making it slower by a magnitude of 10.
func Max(a, b uint64) uint64 {
if a > b {
return a
}
return b
}
// Min returns the smaller integer of the two
// given ones. This is used over the Min function
// in the standard math library because that min function
// has to check for some special floating point cases
// making it slower by a magnitude of 10.
func Min(a, b uint64) uint64 {
if a < b {
return a
}
return b
}
// Mul64 multiples 2 64-bit unsigned integers and checks if they
// lead to an overflow. If they do not, it returns the result
// without an error.

View File

@@ -294,80 +294,6 @@ func TestPowerOf2(t *testing.T) {
}
}
func TestMaxValue(t *testing.T) {
tests := []struct {
a uint64
b uint64
result uint64
}{
{
a: 10,
b: 8,
result: 10,
},
{
a: 300,
b: 256,
result: 300,
},
{
a: 1200,
b: 1024,
result: 1200,
},
{
a: 4500,
b: 4096,
result: 4500,
},
{
a: 9999,
b: 9999,
result: 9999,
},
}
for _, tt := range tests {
require.Equal(t, tt.result, math.Max(tt.a, tt.b))
}
}
func TestMinValue(t *testing.T) {
tests := []struct {
a uint64
b uint64
result uint64
}{
{
a: 10,
b: 8,
result: 8,
},
{
a: 300,
b: 256,
result: 256,
},
{
a: 1200,
b: 1024,
result: 1024,
},
{
a: 4500,
b: 4096,
result: 4096,
},
{
a: 9999,
b: 9999,
result: 9999,
},
}
for _, tt := range tests {
require.Equal(t, tt.result, math.Min(tt.a, tt.b))
}
}
func TestMul64(t *testing.T) {
type args struct {
a uint64