Skip to content

math.big: replace division with Knuth#25242

Merged
spytheman merged 1 commit into
vlang:masterfrom
tankf33der:knuth64
Sep 5, 2025
Merged

math.big: replace division with Knuth#25242
spytheman merged 1 commit into
vlang:masterfrom
tankf33der:knuth64

Conversation

@tankf33der

Copy link
Copy Markdown
Contributor

I am pleased and relieved to present a patch for transitioning to Knuth's division.

The patch consists of two parts: the first is a reorganization of division processing to reduce memory reallocation, and the second is Knuth's division itself.

Testing of the new division was conducted on random numbers of random length with over 20 billion runs, and if to-from string conversion is included, the number is even higher. Even special edge-case tests were created for dividing numbers that are multiples of 60 bits.

Division performance will significantly improve. Now, dividing a number with 366k digits by one half its length is over 100+ times faster.

The overall comparison chart of the two division methods is presented below:
division

To followers: If you have code that uses the math.big module, you have a great opportunity to test it before the merge.

@huly-for-github

Copy link
Copy Markdown

Connected to Huly®: V_0.6-24782

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Excellent work.
Thank you @tankf33der for improving math.big 🙇🏻 .

@spytheman spytheman merged commit 1820a55 into vlang:master Sep 5, 2025
79 checks passed
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