Skip to content

Conversation

@tkfu
Copy link

@tkfu tkfu commented Dec 18, 2025

This commit started off because I wanted to remove MPFR as a dependency. After an initially-incorrect attempt at doing so in #161, and a nice review by @PlasmaPower, I discovered two more problems. First, the test suite didn't have any tests verifying that MPFR actually fixed the problem it was introduced to fix (correctly rounding results like 0.1*1000 to 100 instead of 99). Second, MPFR gets 0.1*1000 right, but still makes rounding mistakes in other cases--I found this out by doing some fuzzing after my initial incorrect patch.

So now I've replaced MPFR with exact rational math in libgmp, and added regression tests for the rounding errors in string parsing. To do this, I had to do the parsing manually; I followed the same regex approach that the existing bs_size_new_from_str function uses.

@vojtechtrefny
Copy link
Member

Jenkins, ok to test.

This commit started off because I wanted to remove MPFR as a dependency.
After an initially-incorrect attempt at doing so, I discovered two more
problems. First, the test suite didn't have any tests verifying that MPFR
actually fixed the problem it was introduced to fix (correctly rounding
results like 0.1*1000 to 100 instead of 99). Second, MPFR gets 0.1*1000,
but still makes rounding mistakes in other cases--I found this out by
fuzzing after my initial incorrect patch.

So now I've replaced MPFR with exact rational math in libgmp, and added
regression tests for the rounding errors in string parsing. To do this, I
had to do the parsing manually; I followed the same regex approach that
the existing function uses.

Signed-off-by: Jon Oster <jon.i.oster@gmail.com>
@tkfu tkfu force-pushed the feat/use-rational-arithmetic branch from f84dab9 to 4797c5d Compare December 19, 2025 13:26
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.

2 participants