Skip to content

feat: Add AsRat() *big.Rat for fractions for easy use and refactor fraction comparison#396

Open
Kybxd wants to merge 1 commit intomasterfrom
wellknown-util
Open

feat: Add AsRat() *big.Rat for fractions for easy use and refactor fraction comparison#396
Kybxd wants to merge 1 commit intomasterfrom
wellknown-util

Conversation

@Kybxd
Copy link
Copy Markdown
Collaborator

@Kybxd Kybxd commented Apr 16, 2026

This MR introduces significant improvements to the fraction comparison functionality in the wellknown utility package:

Changes Made

  • Refactored fraction comparison logic: Replaced cross-multiplication approach with math/big.Rat for precise fraction comparisons
  • Added Fraction.AsRat() method: Converts Fraction protobuf messages to big.Rat type for mathematical operations
  • Added Fraction.Cmp() method: Provides a cleaner interface for comparing fractions using comparator objects
  • Removed deprecated LocalTime function: Eliminated unused timestamp utility that was redundant with protobuf's built-in functionality

Benefits

  • Improved accuracy: math/big.Rat provides exact rational number arithmetic, eliminating potential integer overflow issues
  • Better maintainability: Cleaner code structure with dedicated comparison methods
  • Reduced dependencies: Removed unnecessary timestamp-related imports

Testing

  • All existing comparison tests continue to pass with the new implementation
  • The refactored logic maintains backward compatibility while improving precision

Discussion

  • Should we change tableaupb.Fraction's field type from int32 to int64 to adapt to *big.Rat?

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.04%. Comparing base (5a4e7fc) to head (da5b148).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #396      +/-   ##
==========================================
- Coverage   74.05%   74.04%   -0.02%     
==========================================
  Files          87       87              
  Lines        8819     8806      -13     
==========================================
- Hits         6531     6520      -11     
+ Misses       1718     1716       -2     
  Partials      570      570              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant