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

Mixed integer ops #1

Merged
merged 3 commits into from
Aug 4, 2022
Merged

Mixed integer ops #1

merged 3 commits into from
Aug 4, 2022

Conversation

pedromfedricci
Copy link
Owner

@pedromfedricci pedromfedricci commented Aug 4, 2022

Implement mixed arithmetic operations for Constrained types.
Pairing with the feature: #![feature(mixed_integer_ops)].

// `uX` means: `u8`, `u16`, `u32`, `u64`, `u128` and `usize`.
// `iX` means: `i8`, `i16`, `i32`, `i64`, `i128` and `isize`.

impl<const MIN: uX, const MAX: uX, const DEF: uX> ConstrainedUX<MIN, MAX, DEF> {
    pub const fn checked_add_signed(self, value: iX) -> Option<Self>;
    pub const fn overflowing_add_signed(self, iX) -> (Self, bool);
    pub const fn saturating_add_signed(self, iX) -> Self;
    pub const fn wrapping_add_signed(self, iX) -> Self;
    pub const fn try_add_signed(self, iX) -> Result<Self, ConstrainedUXError>;
}

impl<const MIN: iX, const MAX: iX, const DEF: iX> ConstrainedIX<MIN, MAX, DEF> {
    pub const fn checked_add_unsigned(self, uX) -> Option<Self>;
    pub const fn overflowing_add_unsigned(self, uX) -> (Self, bool);
    pub const fn saturating_add_unsigned(self, uX) -> Self;
    pub const fn wrapping_add_unsigned(self, uX) -> Self;
    pub const fn try_add_unsigned(self, uX) -> Result<Self, MaxIXError>;

    pub const fn checked_sub_unsigned(self, uX) -> Option<Self>;
    pub const fn overflowing_sub_unsigned(self, uX) -> (Self, bool);
    pub const fn saturating_sub_unsigned(self, uX) -> Self;
    pub const fn wrapping_sub_unsigned(self, uX) -> Self;
    pub const fn try_sub_unsigned(self, uX) -> Result<Self, MinIXError>;
}

@codecov-commenter
Copy link

Codecov Report

Merging #1 (3ecb140) into main (8e1ddf8) will increase coverage by 0.84%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##             main        #1      +/-   ##
===========================================
+ Coverage   99.15%   100.00%   +0.84%     
===========================================
  Files           3         3              
  Lines         471       645     +174     
===========================================
+ Hits          467       645     +178     
+ Misses          4         0       -4     
Impacted Files Coverage Δ
src/macros/common.rs 100.00% <100.00%> (ø)
src/macros/int.rs 100.00% <100.00%> (+2.16%) ⬆️
src/macros/uint.rs 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@pedromfedricci pedromfedricci merged commit d869f59 into main Aug 4, 2022
@pedromfedricci pedromfedricci deleted the mixed_integer_ops branch August 4, 2022 03:33
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.

2 participants