Skip to content

Commit

Permalink
Merge #134
Browse files Browse the repository at this point in the history
134: Release 0.2.6 r=cuviper a=cuviper



Co-authored-by: Hactar <6060305+HactarCE@users.noreply.github.com>
Co-authored-by: Josh Stone <cuviper@gmail.com>
  • Loading branch information
3 people authored Jan 27, 2020
2 parents 46ce3b4 + 6d58f6d commit fc3aefe
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ categories = [ "algorithms", "data-structures", "science" ]
license = "MIT/Apache-2.0"
name = "num-bigint"
repository = "https://github.com/rust-num/num-bigint"
version = "0.2.5"
version = "0.2.6"
readme = "README.md"
build = "build.rs"

Expand Down
8 changes: 8 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Release 0.2.6 (2020-01-27)

- [Fix the promotion of negative `isize` in `BigInt` assign-ops][133].

**Contributors**: @cuviper, @HactarCE

[133]: https://github.com/rust-num/num-bigint/pull/133

# Release 0.2.5 (2020-01-09)

- [Updated the `autocfg` build dependency to 1.0][126].
Expand Down
2 changes: 1 addition & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ macro_rules! promote_signed_scalars {
macro_rules! promote_signed_scalars_assign {
(impl $imp:ident for $res:ty, $method:ident) => {
promote_scalars_assign!(impl $imp<i32> for $res, $method, i8, i16);
promote_scalars_assign!(impl $imp<UsizePromotion> for $res, $method, isize);
promote_scalars_assign!(impl $imp<IsizePromotion> for $res, $method, isize);
}
}

Expand Down
22 changes: 14 additions & 8 deletions tests/bigint_scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fn test_scalar_add() {
fn check(x: &BigInt, y: &BigInt, z: &BigInt) {
let (x, y, z) = (x.clone(), y.clone(), z.clone());
assert_signed_scalar_op!(x + y == z);
assert_signed_scalar_assign_op!(x += y == z);
}

for elm in SUM_TRIPLES.iter() {
Expand All @@ -43,6 +44,7 @@ fn test_scalar_sub() {
fn check(x: &BigInt, y: &BigInt, z: &BigInt) {
let (x, y, z) = (x.clone(), y.clone(), z.clone());
assert_signed_scalar_op!(x - y == z);
assert_signed_scalar_assign_op!(x -= y == z);
}

for elm in SUM_TRIPLES.iter() {
Expand All @@ -68,6 +70,7 @@ fn test_scalar_mul() {
fn check(x: &BigInt, y: &BigInt, z: &BigInt) {
let (x, y, z) = (x.clone(), y.clone(), z.clone());
assert_signed_scalar_op!(x * y == z);
assert_signed_scalar_assign_op!(x *= y == z);
}

for elm in MUL_TRIPLES.iter() {
Expand Down Expand Up @@ -98,15 +101,18 @@ fn test_scalar_div_rem() {
assert!(q == *ans_q);
assert!(r == *ans_r);

let b = BigInt::from(b);
let (a, b, ans_q, ans_r) = (a.clone(), b.clone(), ans_q.clone(), ans_r.clone());
assert_op!(a / b == ans_q);
assert_op!(a % b == ans_r);

if b <= i32::max_value() as u32 {
let nb = -(b as i32);
assert_op!(a / nb == -ans_q.clone());
assert_op!(a % nb == ans_r);
}
assert_signed_scalar_op!(a / b == ans_q);
assert_signed_scalar_op!(a % b == ans_r);
assert_signed_scalar_assign_op!(a /= b == ans_q);
assert_signed_scalar_assign_op!(a %= b == ans_r);

let nb = -b;
assert_signed_scalar_op!(a / nb == -ans_q.clone());
assert_signed_scalar_op!(a % nb == ans_r);
assert_signed_scalar_assign_op!(a /= nb == -ans_q.clone());
assert_signed_scalar_assign_op!(a %= nb == ans_r);
}

fn check(a: &BigInt, b: u32, q: &BigInt, r: &BigInt) {
Expand Down
7 changes: 7 additions & 0 deletions tests/biguint_scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fn test_scalar_add() {
fn check(x: &BigUint, y: &BigUint, z: &BigUint) {
let (x, y, z) = (x.clone(), y.clone(), z.clone());
assert_unsigned_scalar_op!(x + y == z);
assert_unsigned_scalar_assign_op!(x += y == z);
}

for elm in SUM_TRIPLES.iter() {
Expand All @@ -33,6 +34,7 @@ fn test_scalar_sub() {
fn check(x: &BigUint, y: &BigUint, z: &BigUint) {
let (x, y, z) = (x.clone(), y.clone(), z.clone());
assert_unsigned_scalar_op!(x - y == z);
assert_unsigned_scalar_assign_op!(x -= y == z);
}

for elm in SUM_TRIPLES.iter() {
Expand All @@ -51,6 +53,7 @@ fn test_scalar_mul() {
fn check(x: &BigUint, y: &BigUint, z: &BigUint) {
let (x, y, z) = (x.clone(), y.clone(), z.clone());
assert_unsigned_scalar_op!(x * y == z);
assert_unsigned_scalar_assign_op!(x *= y == z);
}

for elm in MUL_TRIPLES.iter() {
Expand All @@ -76,6 +79,8 @@ fn test_scalar_div_rem() {
let (x, y, z, r) = (x.clone(), y.clone(), z.clone(), r.clone());
assert_unsigned_scalar_op!(x / y == z);
assert_unsigned_scalar_op!(x % y == r);
assert_unsigned_scalar_assign_op!(x /= y == z);
assert_unsigned_scalar_assign_op!(x %= y == r);
}

for elm in MUL_TRIPLES.iter() {
Expand Down Expand Up @@ -104,6 +109,8 @@ fn test_scalar_div_rem() {
check(&a, &b, &c, &d);
assert_unsigned_scalar_op!(a / b == c);
assert_unsigned_scalar_op!(a % b == d);
assert_unsigned_scalar_assign_op!(a /= b == c);
assert_unsigned_scalar_assign_op!(a %= b == d);
}
}
}
46 changes: 46 additions & 0 deletions tests/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,49 @@ macro_rules! assert_signed_scalar_op {
$left $op $right == $expected);
};
}

/// Assert that an op works for scalar right
macro_rules! assert_scalar_assign_op {
(($($to:ident),*) $left:ident $op:tt $right:ident == $expected:expr) => {
$(
if let Some(right) = $right.$to() {
let mut left = $left.clone();
assert_eq!({ left $op right; left}, $expected);
}
)*
};
}

#[cfg(not(has_i128))]
macro_rules! assert_unsigned_scalar_assign_op {
($left:ident $op:tt $right:ident == $expected:expr) => {
assert_scalar_assign_op!((to_u8, to_u16, to_u32, to_u64, to_usize)
$left $op $right == $expected);
};
}

#[cfg(has_i128)]
macro_rules! assert_unsigned_scalar_assign_op {
($left:ident $op:tt $right:ident == $expected:expr) => {
assert_scalar_assign_op!((to_u8, to_u16, to_u32, to_u64, to_usize, to_u128)
$left $op $right == $expected);
};
}

#[cfg(not(has_i128))]
macro_rules! assert_signed_scalar_assign_op {
($left:ident $op:tt $right:ident == $expected:expr) => {
assert_scalar_assign_op!((to_u8, to_u16, to_u32, to_u64, to_usize,
to_i8, to_i16, to_i32, to_i64, to_isize)
$left $op $right == $expected);
};
}

#[cfg(has_i128)]
macro_rules! assert_signed_scalar_assign_op {
($left:ident $op:tt $right:ident == $expected:expr) => {
assert_scalar_assign_op!((to_u8, to_u16, to_u32, to_u64, to_usize, to_u128,
to_i8, to_i16, to_i32, to_i64, to_isize, to_i128)
$left $op $right == $expected);
};
}

0 comments on commit fc3aefe

Please sign in to comment.