Skip to content

crmath: add ScaleUint64#18

Merged
RaduBerinde merged 1 commit intocockroachdb:mainfrom
RaduBerinde:crmath
Jul 18, 2025
Merged

crmath: add ScaleUint64#18
RaduBerinde merged 1 commit intocockroachdb:mainfrom
RaduBerinde:crmath

Conversation

@RaduBerinde
Copy link
Member

@RaduBerinde RaduBerinde commented Jul 18, 2025

Add an overflow-safe scaling function.


This change is Reviewable

Add an overflow-safe scaling function.
@RaduBerinde RaduBerinde requested review from Copilot and jbowens July 18, 2025 16:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new overflow-safe scaling function ScaleUint64 to the crmath package that computes the ceiling of x*a/b while handling potential overflow conditions safely.

  • Implements ScaleUint64 function with optimized fast path for smaller values and overflow protection
  • Includes comprehensive test coverage with edge cases, randomized testing, and verification against big.Int implementation
  • Handles division by zero with panic behavior and overflow cases by clamping to math.MaxUint64

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
crmath/scale.go Implements the main ScaleUint64 function with fast/slow path optimization and overflow handling
crmath/scale_test.go Comprehensive test suite including edge cases, randomized testing, and panic verification

@RaduBerinde RaduBerinde requested a review from annrpom July 18, 2025 21:28
Copy link

@annrpom annrpom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@RaduBerinde
Copy link
Member Author

TFTR!

@RaduBerinde RaduBerinde merged commit 7ff5051 into cockroachdb:main Jul 18, 2025
6 checks passed
@RaduBerinde RaduBerinde deleted the crmath branch July 18, 2025 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants