Add convenience macro for BigInt
All checks were successful
timw4mail/rusty-numbers/pipeline/head This commit looks good
All checks were successful
timw4mail/rusty-numbers/pipeline/head This commit looks good
This commit is contained in:
parent
322ccfe78a
commit
bbfada5c0f
@ -15,6 +15,17 @@ pub struct BigInt {
|
||||
sign: Sign,
|
||||
}
|
||||
|
||||
/// Create a [BigInt](bigint/struct.BigInt.html) type with signed or unsigned number literals
|
||||
#[macro_export]
|
||||
macro_rules! big_int {
|
||||
($w:literal) => {
|
||||
$crate::bigint::BigInt::from($w)
|
||||
};
|
||||
(-$x:literal) => {
|
||||
$crate::bigint::BigInt::from(-$x)
|
||||
};
|
||||
}
|
||||
|
||||
impl Default for BigInt {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
@ -439,6 +450,17 @@ mod tests {
|
||||
assert_eq!(int.inner[0], 45usize)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_macro() {
|
||||
let a = big_int!(75);
|
||||
let b = BigInt::from(75);
|
||||
assert_eq!(a, b);
|
||||
|
||||
let a = big_int!(-75);
|
||||
let b = BigInt::from(-75);
|
||||
assert_eq!(a, b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trim_zeros() {
|
||||
let mut lotsoftrailing = BigInt {
|
||||
|
@ -160,7 +160,6 @@ macro_rules! impl_int {
|
||||
self == 0
|
||||
}
|
||||
|
||||
#[cfg_attr(tarpaulin, skip)]
|
||||
fn max_value() -> $type {
|
||||
<$type>::max_value()
|
||||
}
|
||||
@ -253,7 +252,6 @@ macro_rules! impl_unsigned {
|
||||
let (x, y) = (min(x, y), max(x, y));
|
||||
Self::stein_gcd((y - x) >> 1, x)
|
||||
}
|
||||
#[cfg_attr(tarpaulin, skip)]
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user