Skip to content

Commit ccd54a1

Browse files
committed
Merge #28
28: Implement is_one for BigUint and BigInt. r=cuviper a=clarcharr Won't work until a newer version of `num-traits` is pushed, but I figured I'd offer these now.
2 parents d6fc7bc + 12498b2 commit ccd54a1

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ version = "0.1.36"
2929
default-features = false
3030

3131
[dependencies.num-traits]
32-
version = "0.2.0"
32+
version = "0.2.1"
3333
default-features = false
3434
features = ["std"]
3535

src/bigint.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,11 @@ impl One for BigInt {
274274
fn one() -> BigInt {
275275
BigInt::from_biguint(Plus, One::one())
276276
}
277+
278+
#[inline]
279+
fn is_one(&self) -> bool {
280+
self.sign == Plus && self.data.is_one()
281+
}
277282
}
278283

279284
impl Signed for BigInt {

src/biguint.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,11 @@ impl One for BigUint {
417417
fn one() -> BigUint {
418418
BigUint::new(vec![1])
419419
}
420+
421+
#[inline]
422+
fn is_one(&self) -> bool {
423+
self.data[..] == [1]
424+
}
420425
}
421426

422427
impl Unsigned for BigUint {}

0 commit comments

Comments
 (0)