Skip to content

Commit f91db6b

Browse files
author
Clar Charr
committed
Implement is_one for BigUint and BigInt.
1 parent 1cf2196 commit f91db6b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

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
@@ -415,6 +415,11 @@ impl One for BigUint {
415415
fn one() -> BigUint {
416416
BigUint::new(vec![1])
417417
}
418+
419+
#[inline]
420+
fn is_one(&self) -> bool {
421+
self.data[..] == [1]
422+
}
418423
}
419424

420425
impl Unsigned for BigUint {}

0 commit comments

Comments
 (0)