Skip to content

math.big: restore and refactor str() and integer_from_string()#25154

Merged
spytheman merged 1 commit into
vlang:masterfrom
tankf33der:str_to_from
Aug 22, 2025
Merged

math.big: restore and refactor str() and integer_from_string()#25154
spytheman merged 1 commit into
vlang:masterfrom
tankf33der:str_to_from

Conversation

@tankf33der

Copy link
Copy Markdown
Contributor

To transition to a 60-bit base for math.big, it is necessary to return and rewrite the code for str() and integer_from_string(). This is also a good opportunity to additionally perform refactoring.

Tests show that for multi-thousand digit numbers, str() will now be ~14x faster, and integer_from_string() ~11x faster.

The repo already contains the necessary tests for all radix.

Patch passed tests against gmplib.

@huly-for-github

Copy link
Copy Markdown

Connected to Huly®: V_0.6-23810

Comment thread vlib/math/big/integer.v

const digit_array = '0123456789abcdefghijklmnopqrstuvwxyz'.bytes()
// vfmt off
const radix_options = {

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.

The keys seem to have very low cardinality, would not an array instead of a map be better? It can eliminate one hash per key lookup, and the array data will have better cache locality.

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.

Although radix_options does not seem to be used in loops, so it may not matter much.

@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.
Thank you 🙇🏻‍♂️.

@spytheman spytheman merged commit d8d125b into vlang:master Aug 22, 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