-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add strict methods, midpoint methods
- Loading branch information
1 parent
52dcea2
commit 6d7c7a7
Showing
19 changed files
with
464 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
- Add optional borsh support | ||
- Add `digits_mut` method to unsigned integers. | ||
- `As` and `CastFrom` traits no longer const, as const trait support removed from latest nightly. | ||
- `As` and `CastFrom` traits no longer const, as const trait support removed from latest nightly. | ||
- `cast_signed` method for unsigned integers. | ||
- `cast_unsigned` method for signed integers. | ||
- `midpoint` method for unsigned integers. | ||
- `carrying_add` and `borrowing_sub` methods for signed integers. | ||
- strict methods added. | ||
- added `(bnum) ` prefix to error messages that were lacking it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
macro_rules! bigint_helpers { | ||
($BUint: ident, $BInt: ident, $Digit: ident) => { | ||
#[doc = doc::bigint_helpers::impl_desc!()] | ||
impl<const N: usize> $BInt<N> { | ||
crate::int::bigint_helpers::impls!(I); | ||
} | ||
|
||
#[cfg(test)] | ||
paste::paste! { | ||
mod [<$Digit _digit_tests>] { | ||
use crate::test::types::big_types::$Digit::*; | ||
crate::int::bigint_helpers::tests!(itest); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
use crate::doc; | ||
|
||
crate::macro_impl!(bigint_helpers); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
macro_rules! strict { | ||
($BUint: ident, $BInt: ident, $Digit: ident) => { | ||
#[doc = doc::strict::impl_desc!()] | ||
impl<const N: usize> $BInt<N> { | ||
crate::int::strict::impls!(I); | ||
|
||
#[doc = doc::strict::strict_abs!(I)] | ||
#[must_use = doc::must_use_op!()] | ||
#[inline] | ||
pub const fn strict_abs(self) -> Self { | ||
crate::errors::option_expect!( | ||
self.checked_abs(), | ||
crate::errors::err_msg!("attempt to negate with overflow") | ||
) | ||
} | ||
|
||
#[doc = doc::strict::strict_add_unsigned!(I)] | ||
#[must_use = doc::must_use_op!()] | ||
#[inline] | ||
pub const fn strict_add_unsigned(self, rhs: $BUint<N>) -> Self { | ||
crate::errors::option_expect!( | ||
self.checked_add_unsigned(rhs), | ||
crate::errors::err_msg!("attempt to add with overflow") | ||
) | ||
} | ||
|
||
#[doc = doc::strict::strict_sub_unsigned!(I)] | ||
#[must_use = doc::must_use_op!()] | ||
#[inline] | ||
pub const fn strict_sub_unsigned(self, rhs: $BUint<N>) -> Self { | ||
crate::errors::option_expect!( | ||
self.checked_sub_unsigned(rhs), | ||
crate::errors::err_msg!("attempt to subtract with overflow") | ||
) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
paste::paste! { | ||
mod [<$Digit _digit_tests>] { | ||
use crate::test::types::big_types::$Digit::*; | ||
crate::int::strict::tests!(itest); | ||
|
||
test_bignum! { | ||
function: <itest>::strict_abs(a: itest), | ||
skip: a.checked_abs().is_none() | ||
} | ||
test_bignum! { | ||
function: <itest>::strict_add_unsigned(a: itest, b: utest), | ||
skip: a.checked_add_unsigned(b).is_none() | ||
} | ||
test_bignum! { | ||
function: <itest>::strict_sub_unsigned(a: itest, b: utest), | ||
skip: a.checked_sub_unsigned(b).is_none() | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
use crate::doc; | ||
|
||
crate::macro_impl!(strict); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
macro_rules! strict { | ||
($BUint: ident, $BInt: ident, $Digit: ident) => { | ||
#[doc = doc::strict::impl_desc!()] | ||
impl<const N: usize> $BUint<N> { | ||
crate::int::strict::impls!(U); | ||
|
||
#[doc = doc::strict::strict_add_signed!(U)] | ||
#[must_use = doc::must_use_op!()] | ||
#[inline] | ||
pub const fn strict_add_signed(self, rhs: $BInt<N>) -> Self { | ||
crate::errors::option_expect!( | ||
self.checked_add_signed(rhs), | ||
crate::errors::err_msg!("attempt to add with overflow") | ||
) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
paste::paste! { | ||
mod [<$Digit _digit_tests>] { | ||
use crate::test::types::big_types::$Digit::*; | ||
|
||
crate::int::strict::tests!(utest); | ||
|
||
test_bignum! { | ||
function: <utest>::strict_add_signed(a: utest, b: itest), | ||
skip: a.checked_add_signed(b).is_none() | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
use crate::doc; | ||
|
||
crate::macro_impl!(strict); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
use crate::doc; | ||
|
||
macro_rules! impl_desc { | ||
() => { | ||
"Bigint helper methods: common functions used to implement big integer arithmetic." | ||
}; | ||
} | ||
|
||
pub(crate) use impl_desc; | ||
|
||
doc::link_doc_comment!(carrying_add, borrowing_sub, widening_mul, carrying_mul); |
Oops, something went wrong.