math.big: make is_odd public and add test cases #18916
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes the internal
is_odd
function public for the reason that external users of the library cannot directly access thedigits
array. Exposing this function allows a faster method of checking if an integer is odd meaning the caller doesn't have to do something cheeky likea.int() & 1 == 1
.Also a reinforcement on the method's safety by checking the length of the digit array. This is preferable over checking if the signum is 0, because the signum could be incorrect (for whatever reason).
馃 Generated by Copilot at 29c4838
This pull request improves the testing and implementation of the
is_odd
function for big integers. It adds more test cases, makes the function public, and handles the zero input case. It also moves the function to thebig_test.v
file.馃 Generated by Copilot at 29c4838
is_odd
function public and handle zero input (link)is_odd
function fromvlib/math/big/integer.v
tovlib/math/big/big_test.v
(link)is_odd_test_data
with various test cases for theis_odd
function (link)test_is_odd
that asserts the correct output of theis_odd
function for each test case (link)