dashu-int 0.6.0

Arbitrary-precision integer math library for Rust, balancing ergonomics and efficiency. Provides UBig and IBig (unsigned and signed), with small values inlined on the stack. Efficient arithmetic, modular arithmetic, and number theory (pow, ilog, gcd, gcd_ext); two's-complement bit operations; parsing and formatting in base 2-36; optional serde, rand, num-traits, rkyv, and zeroize.
Documentation
//! Formatting of Montgomery-form values.

use super::repr::Montgomery;
use core::fmt::{self, Binary, Debug, Display, Formatter, LowerHex, Octal, UpperHex};

macro_rules! impl_fmt_for_monty {
    ($t:ident) => {
        impl $t for Montgomery<'_> {
            fn fmt(&self, f: &mut Formatter) -> fmt::Result {
                $t::fmt(&self.residue(), f)?;
                f.write_str(" (mod ")?;
                $t::fmt(&self.modulus(), f)?;
                f.write_str(")")
            }
        }
    };
}

impl_fmt_for_monty!(Display);
impl_fmt_for_monty!(Binary);
impl_fmt_for_monty!(Octal);
impl_fmt_for_monty!(LowerHex);
impl_fmt_for_monty!(UpperHex);

impl Debug for Montgomery<'_> {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        let residue = self.residue();
        let modulus = self.modulus();
        if f.alternate() {
            f.debug_struct("Montgomery")
                .field("residue", &residue)
                .field("modulus", &modulus)
                .finish()
        } else {
            Debug::fmt(&residue, f)?;
            f.write_str(" (mod ")?;
            Debug::fmt(&self.modulus(), f)?;
            f.write_str(")")
        }
    }
}