Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ macro_rules! impl_for_primitives {
#[inline]
#[allow(unused_comparisons)] // Both signed and unsigned integers use this.
#[allow(clippy::cast_possible_truncation)] // Unreachable.
fn partial_cmp(&self, other: &$t) -> Option<Ordering> {
if *other < 0 {
fn partial_cmp(&self, &other: &$t) -> Option<Ordering> {
if other < 0 {
return Some(Ordering::Greater);
}

if <$t>::BITS <= u64::BITS {
let Ok(self_t) = u64::try_from(self) else {
return Some(Ordering::Greater);
};
self_t.partial_cmp(&(*other as u64))
self_t.partial_cmp(&(other as u64))
} else {
let Ok(self_t) = u128::try_from(self) else {
return Some(Ordering::Greater);
};
self_t.partial_cmp(&(*other as u128))
self_t.partial_cmp(&(other as u128))
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ macro_rules! impl_fmt {
($tr:path; $base:ty, $base_char:literal) => {
impl<const BITS: usize, const LIMBS: usize> $tr for Uint<BITS, LIMBS> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Ok(small) = u64::try_from(self) {
return <u64 as $tr>::fmt(&small, f);
}
if let Ok(small) = u128::try_from(self) {
return <u128 as $tr>::fmt(&small, f);
}

// Use `BITS` for all bases since `generic_const_exprs` is not yet stable.
let mut buffer = DisplayBuffer::<BITS>::new();
let mut first = true;
Expand Down
Loading