Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[#1953] Revert "Fix zero division panic"
This reverts commit 9ab7d2e.

This reverts commit 4b916c3.
  • Loading branch information
fivitti committed Aug 12, 2025
commit f56d9571147da5a2be97bf000c107cb56e15dea1
2 changes: 0 additions & 2 deletions backend/util/bigcounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ func (n *BigCounter) DivideBy(other *BigCounter) float64 {
func (n *BigCounter) DivideSafeBy(other *BigCounter) float64 {
if !other.isExtended() && other.base == 0 {
return 0.0
} else if other.isExtended() && other.extended.Cmp(big.NewInt(0)) == 0 {
return 0.0
}
return n.DivideBy(other)
}
Expand Down
18 changes: 1 addition & 17 deletions backend/util/bigcounter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestBigCounterDivideBigIntByInt64InInt64Range(t *testing.T) {
require.EqualValues(t, float64(math.MaxUint64), res)
}

// Test that safe divide doesn't panic for the base counter.
// Test that safe divide doesn't panic.
func TestBigCounterSafeDivideByZero(t *testing.T) {
// Arrange
counter1 := NewBigCounter(1)
Expand All @@ -201,22 +201,6 @@ func TestBigCounterSafeDivideByZero(t *testing.T) {
require.Zero(t, res)
}

// Test that safe divide doesn't panic for the extended counter.
func TestBigCounterSafeDivideByZeroExtended(t *testing.T) {
// Arrange
counter1 := NewBigCounter(1)
counter2 := NewBigCounter(math.MaxUint64).AddUint64(1).
Subtract(
NewBigCounter(math.MaxUint64).AddUint64(1),
)

// Act
res := counter1.DivideSafeBy(counter2)

// Assert
require.Zero(t, res)
}

// Test that safe divide works as standard divide.
func TestBigCounterDivideSafe(t *testing.T) {
// Arrange
Expand Down