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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

math.big: make is_odd public and add test cases #18916

Merged
merged 1 commit into from
Jul 20, 2023

Conversation

phoreverpheebs
Copy link
Contributor

@phoreverpheebs phoreverpheebs commented Jul 20, 2023

This PR makes the internal is_odd function public for the reason that external users of the library cannot directly access the digits 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 like a.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 the big_test.v file.

馃 Generated by Copilot at 29c4838

  • Make the is_odd function public and handle zero input (link)
  • Move the is_odd function from vlib/math/big/integer.v to vlib/math/big/big_test.v (link)
  • Add a new constant is_odd_test_data with various test cases for the is_odd function (link)
  • Add a new test function test_is_odd that asserts the correct output of the is_odd function for each test case (link)

@medvednikov medvednikov merged commit 93b3f1c into vlang:master Jul 20, 2023
42 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.

None yet

2 participants