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

Implement signed and unsigned min and max value. #10

Closed
4 tasks done
Robbepop opened this issue Jan 2, 2018 · 1 comment
Closed
4 tasks done

Implement signed and unsigned min and max value. #10

Robbepop opened this issue Jan 2, 2018 · 1 comment

Comments

@Robbepop
Copy link
Owner

Robbepop commented Jan 2, 2018

In Rust all primitive types provide a min_value and max_value constructor to constructor the minimum representable and maximum representable value respectively. In ApInt this is not directly possible since ApInt itself has no concept of signedness. However, it is possible to achieve a similar effect and provide the same level of functionality by providing constructors that are aware of the signedness.

The proposed API additions are:

  • fn signed_min_value(width: BitWidth) -> ApInt

    Returns the smallest possible ApInt instance with the given BitWidth representing a signed value.

  • fn unsigned_min_value(width: BitWidth) -> ApInt

    Returns the smallest possible ApInt instance with the given BitWidth representing an unsigned value.

  • fn signed_max_value(width: BitWidth) -> ApInt

    Returns the largest possible ApInt instance with the given BitWidth representing a signed value.

  • fn unsigned_max_value(width: BitWidth) -> ApInt

    Returns the largest possible ApInt instance with the given BitWidth representing an unsigned value.

Some higher level data structures that are based on ApInt may later use these explicit constructors in an implicit way. E.g. SignedApInt may provide min_value and max_value directly by simply forwarding to its internal ApInt::signed_min_value and ApInt::signed_max_value.

@Robbepop
Copy link
Owner Author

Robbepop commented Jan 4, 2018

Issue implemented in commit 9d86aa8.

@Robbepop Robbepop closed this as completed Jan 4, 2018
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

No branches or pull requests

1 participant