Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math/unsigned: permit _ separators in Uint128 decimal strings #21461

Merged
merged 6 commits into from
May 8, 2024

Conversation

kimshrier
Copy link
Contributor

Permit '_' separator characters in strings that can be converted to Uint128 values.

This is like the other string -> numeric value conversions for the builtin number types.

I was thinking of doing the same for Uint256 if this change is acceptable for Uint128.

@penguindark
Copy link
Member

May be we need to optimize code like if b_ == '_'.bytes()[0] {
using the bytes() to convert a single char seem a little overkill IMHO.

@kimshrier
Copy link
Contributor Author

I was following the precedent set in the line following my code addition where '0'.bytes()[0] was used. I am more than willing to change my code in order to be both more efficient and more V like.

@kimshrier
Copy link
Contributor Author

I wasn't sure if it was appropriate to compare a rune with a u8. Looks like it is.

@spytheman
Copy link
Member

spytheman commented May 8, 2024

I wasn't sure if it was appropriate to compare a rune with a u8. Looks like it is.

Yes, it is somewhat not pure (from a language perspective), but it makes code like this more compact and readable. Rune literals boil down to u8 values, when used in comparison to known u8 values.

@spytheman spytheman merged commit f71b801 into vlang:master May 8, 2024
62 of 63 checks passed
@kimshrier kimshrier deleted the uint128_separator branch May 8, 2024 15:50
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.

None yet

4 participants