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

add int16 and uint16 operators #1421

Merged
merged 2 commits into from
Jan 14, 2025
Merged

add int16 and uint16 operators #1421

merged 2 commits into from
Jan 14, 2025

Conversation

Yu-zh
Copy link
Collaborator

@Yu-zh Yu-zh commented Jan 3, 2025

No description provided.

Copy link

peter-jerry-ye-code-review bot commented Jan 3, 2025

‼️ This code review is generated by a bot. Please verify the content before trusting it.

Here are three potential issues or observations from the provided git diff output:

  1. Overflow Handling in Int16::op_add and Int16::op_sub:

    • In the Int16::op_add and Int16::op_sub functions, there are test cases that demonstrate overflow and underflow behavior. For example, adding 32767 and 1 results in -32768, which is correct for 16-bit signed integers. However, the comments in the test cases (e.g., // Overflow case) should be more explicit about the expected behavior, especially for developers who may not be familiar with integer overflow in signed 16-bit arithmetic. This could lead to confusion if the behavior is not well-documented.
  2. Inconsistent Naming in Int16::from_int and Int16::to_int:

    • The test cases for Int16::from_int and Int16::to_int use Int::to_int16 and Int16::to_int, respectively. While this is functionally correct, the naming could be more consistent. For example, Int::to_int16 could be renamed to Int::as_int16 to better reflect that it is a conversion function rather than a simple getter. This would make the code more intuitive and easier to understand.
  3. Potential Issue with UInt16::op_div:

    • In the UInt16::op_div function, there is a test case where 65535 / 1 is expected to return 65535. While this is correct, there is no test case for division by zero, which should be handled explicitly to avoid runtime errors. Adding a test case for division by zero and ensuring that the function either handles it gracefully or throws an appropriate error would improve the robustness of the code.

These observations are not necessarily bugs but rather areas where the code could be improved for clarity, consistency, and robustness.

@coveralls
Copy link
Collaborator

coveralls commented Jan 3, 2025

Pull Request Test Coverage Report for Build 4750

Details

  • 14 of 20 (70.0%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.05%) to 83.048%

Changes Missing Coverage Covered Lines Changed/Added Lines %
int16/int16.mbt 7 8 87.5%
uint16/uint16.mbt 7 8 87.5%
builtin/console.mbt 0 2 0.0%
builtin/show.mbt 0 2 0.0%
Totals Coverage Status
Change from base Build 4748: -0.05%
Covered Lines: 4845
Relevant Lines: 5834

💛 - Coveralls

@bobzhang bobzhang merged commit b45fcd7 into moonbitlang:main Jan 14, 2025
14 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.

3 participants