#![cfg_attr(all(doc, feature = "alloc"), allow(rustdoc::broken_intra_doc_links))]
#[cfg(feature = "alloc")]
use crate::Vec;
use crate::{GcdReturn, IntError as E, IntResult as Result, Num, ValueQuant};
#[cfg(doc)]
use E::{
MismatchedSizes, NoInverse, NonNegativeRequired, NonZeroRequired, NotImplemented, NotSupported,
Overflow,
};
mod impls;
mod r#ref;
pub use r#ref::NumRefInt;
mod auto_impls {
use super::{NumInt, NumRefInt};
#[rustfmt::skip]
impl<T: NumInt> NumRefInt<'_> for &T {}
#[rustfmt::skip]
impl<T: NumInt> NumRefInt<'_> for &mut T {}
}
#[doc = crate::_tags!(num)]
#[doc = crate::_doc_location!("num/dom/int")]
#[expect(unused_variables, reason = "pretty signatures")]
#[rustfmt::skip]
pub trait NumInt: Num {
type OutI;
#[doc = link_impls!["digital_root"]]
fn int_digital_root(self) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_digital_root"]]
fn int_ref_digital_root(&self) -> Result<Self::Out> { E::ni() }
#[doc = link_impls!["digital_root_base"]]
fn int_digital_root_base(self, base: Self::Rhs) -> Result<Self::Out>
where Self: Sized { E::ni() }
#[doc = ref_fn!["int_digital_root_base"]]
fn int_ref_digital_root_base(&self, base: &Self::Rhs) -> Result<Self::Out> { E::ni() }
#[doc = link_impls!["digits"]]
fn int_digits(self) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_digits"]]
fn int_ref_digits(&self) -> Result<Self::Out> { E::ni() }
#[doc = link_impls!["digits_sign"]]
fn int_digits_sign(self) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_digits_sign"]]
fn int_ref_digits_sign(&self) -> Result<Self::Out> { E::ni() }
#[doc = link_impls!["digits_base"]]
fn int_digits_base(self, base: Self::Rhs) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_digits_base"]]
fn int_ref_digits_base(&self, base: &Self::Rhs) -> Result<Self::Out> { E::ni() }
#[doc = link_impls!["digits_base_sign"]]
fn int_digits_base_sign(self, base: Self::Rhs)
-> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_digits_base_sign"]]
fn int_ref_digits_base_sign(&self, base: &Self::Rhs) -> Result<Self::Out> { E::ni() }
#[doc = link_impls!["abs"]]
fn int_abs(self) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_abs"]]
fn int_ref_abs(&self) -> Result<Self::Out> { E::ni() }
#[doc = link_impls!["is_even"]]
fn int_is_even(self) -> Result<bool> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_is_even"]]
fn int_ref_is_even(&self) -> Result<bool> { E::ni() }
#[doc = link_impls!["is_odd"]]
fn int_is_odd(self) -> Result<bool> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_is_odd"]]
fn int_ref_is_odd(&self) -> Result<bool> { E::ni() }
#[doc = link_impls!["gcd"]]
fn int_gcd(self, other: Self::Rhs) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_gcd"]]
fn int_ref_gcd(&self, other: &Self::Rhs) -> Result<Self::Out> { E::ni() }
#[doc = link_impls!["gcd_ext"]]
fn int_gcd_ext(self, other: Self::Rhs)
-> Result<GcdReturn<Self::Out, Self::OutI>> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_gcd_ext"]]
fn int_ref_gcd_ext(&self, other: &Self::Rhs)
-> Result<GcdReturn<Self::Out, Self::OutI>> { E::ni() }
#[doc = link_impls!["lcm"]]
fn int_lcm(self, other: Self::Rhs) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_lcm"]]
fn int_ref_lcm(&self, other: &Self::Rhs) -> Result<Self::Out> { E::ni() }
#[doc = crate::_INT_FORMULA_SCALE!()]
#[doc = link_impls!["scale"]]
fn int_scale(self, min: Self::Rhs, max: Self::Rhs, a: Self::Rhs, b: Self::Rhs)
-> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_scale"]]
fn int_ref_scale(&self, min: &Self::Rhs, max: &Self::Rhs, a: &Self::Rhs, b: &Self::Rhs)
-> Result<Self::Out> { E::ni() }
#[doc = crate::_INT_FORMULA_SCALE!()] #[doc = link_impls!["scale_wrap"]]
fn int_scale_wrap(self, min: Self::Rhs, max: Self::Rhs, a: Self::Rhs, b: Self::Rhs)
-> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_scale_wrap"]]
fn int_ref_scale_wrap(&self, min: &Self::Rhs, max: &Self::Rhs, a: &Self::Rhs, b: &Self::Rhs)
-> Result<Self::Out> { E::ni() }
#[doc = link_impls!["midpoint"]]
fn int_midpoint(self, other: Self::Rhs) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_midpoint"]]
fn int_ref_midpoint(&self, other: &Self::Rhs) -> Result<Self::Out> { E::ni() }
#[doc = crate::_INT_FORMULA_FACTORIAL!()]
#[doc = link_impls!["factorial"]]
fn int_factorial(self) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_factorial"]]
fn int_ref_factorial(&self) -> Result<Self::Out> { E::ni() }
#[doc = crate::_INT_FORMULA_SUBFACTORIAL_RECURSIVE!()]
#[doc = link_impls!["subfactorial"]]
fn int_subfactorial(self) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_subfactorial"]]
fn int_ref_subfactorial(&self) -> Result<Self::Out> { E::ni() }
#[doc = crate::_INT_FORMULA_COMBINE_REP!()]
#[doc = link_impls!["combine"]]
fn int_combine(self, r: Self::Rhs) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_combine"]]
fn int_ref_combine(&self, r: &Self::Rhs) -> Result<Self::Out> { E::ni() }
#[doc = crate::_INT_FORMULA_COMBINE_REP!()]
#[doc = link_impls!["combine_rep"]]
fn int_combine_rep(self, r: Self::Rhs) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_combine_rep"]]
fn int_ref_combine_rep(&self, r: &Self::Rhs) -> Result<Self::Out> { E::ni() }
#[doc = crate::_INT_FORMULA_PERMUTE!()]
#[doc = link_impls!["permute"]]
fn int_permute(self, r: Self::Rhs) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_permute"]]
fn int_ref_permute(&self, r: &Self::Rhs) -> Result<Self::Out> { E::ni() }
#[doc = crate::_INT_FORMULA_PERMUTE_REP!()]
#[doc = link_impls!["permute_rep"]]
fn int_permute_rep(self, r: Self::Rhs) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_permute_rep"]]
fn int_ref_permute_rep(&self, r: &Self::Rhs) -> Result<Self::Out> { E::ni() }
#[doc = link_impls!["div_rem"]]
fn int_div_rem(self, b: Self::Rhs) -> Result<[Self::Out; 2]> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_div_rem"]]
fn int_ref_div_rem(&self, b: &Self::Rhs) -> Result<[Self::Out; 2]> { E::ni() }
#[doc = crate::_INT_NOTATION_DIV_CEIL!()]
#[doc = link_impls!["div_ceil"]]
fn int_div_ceil(self, b: Self::Rhs) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_div_ceil"]]
fn int_ref_div_ceil(&self, b: &Self::Rhs) -> Result<Self::Out> { E::ni() }
#[doc = crate::_INT_NOTATION_DIV_FLOOR!()]
#[doc = link_impls!["div_floor"]]
fn int_div_floor(self, b: Self::Rhs) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_div_floor"]]
fn int_ref_div_floor(&self, b: &Self::Rhs) -> Result<Self::Out> { E::ni() }
#[doc = link_impls!["div_ties_away"]]
fn int_div_ties_away(self, b: Self::Rhs) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_div_ties_away"]]
fn int_ref_div_ties_away(&self, b: &Self::Rhs) -> Result<Self::Out> { E::ni() }
#[doc = link_impls!["div_ties_towards"]]
fn int_div_ties_towards(self, b: Self::Rhs) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_div_ties_towards"]]
fn int_ref_div_ties_towards(&self, b: &Self::Rhs) -> Result<Self::Out> { E::ni() }
#[doc = link_impls!["div_ties_even"]]
fn int_div_ties_even(self, b: Self::Rhs) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_div_ties_even"]]
fn int_ref_div_ties_even(&self, b: &Self::Rhs) -> Result<Self::Out> { E::ni() }
#[doc = link_impls!["div_ties_odd"]]
fn int_div_ties_odd(self, b: Self::Rhs) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_div_ties_odd"]]
fn int_ref_div_ties_odd(&self, b: &Self::Rhs) -> Result<Self::Out> { E::ni() }
#[cfg(feature = "alloc")]
#[cfg_attr(nightly_doc, doc(cfg(feature = "alloc")))]
#[doc = link_impls!["factors"]]
fn int_factors(self) -> Result<Vec<Self::Out>> where Self: Sized { E::ni() }
#[cfg(feature = "alloc")]
#[cfg_attr(nightly_doc, doc(cfg(feature = "alloc")))]
#[doc = ref_fn!["int_factors"]]
fn int_ref_factors(&self) -> Result<Vec<Self::Out>> { E::ni() }
#[cfg(feature = "alloc")]
#[cfg_attr(nightly_doc, doc(cfg(feature = "alloc")))]
#[doc = link_impls!["factors_proper"]]
fn int_factors_proper(self) -> Result<Vec<Self::Out>> where Self: Sized { E::ni() }
#[cfg(feature = "alloc")]
#[cfg_attr(nightly_doc, doc(cfg(feature = "alloc")))]
#[doc = ref_fn!["int_factors_proper"]]
fn int_ref_factors_proper(&self) -> Result<Vec<Self::Out>> { E::ni() }
#[cfg(feature = "alloc")]
#[cfg_attr(nightly_doc, doc(cfg(feature = "alloc")))]
#[doc = link_impls!["factors_prime"]]
fn int_factors_prime(self) -> Result<Vec<Self::Out>> where Self: Sized { E::ni() }
#[cfg(feature = "alloc")]
#[cfg_attr(nightly_doc, doc(cfg(feature = "alloc")))]
#[doc = ref_fn!["int_factors_prime"]]
fn int_ref_factors_prime(&self) -> Result<Vec<Self::Out>> { E::ni() }
#[cfg(feature = "alloc")]
#[cfg_attr(nightly_doc, doc(cfg(feature = "alloc")))]
#[doc = link_impls!["factors_prime_unique"]]
fn int_factors_prime_unique(self) -> Result<Vec<Self::Out>> where Self: Sized { E::ni() }
#[cfg(feature = "alloc")]
#[cfg_attr(nightly_doc, doc(cfg(feature = "alloc")))]
#[doc = ref_fn!["int_factors_prime_unique"]]
fn int_ref_factors_prime_unique(&self) -> Result<Vec<Self::Out>> { E::ni() }
#[doc = link_impls!["factors_buf"]]
fn int_factors_buf(self, fbuf: &mut [Self::Out], upfbuf: &mut [Self::Out])
-> Result<(usize, usize)> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_factors_buf"]]
fn int_ref_factors_buf(&self, fbuf: &mut [Self::Out], upfbuf: &mut [Self::Out])
-> Result<(usize, usize)> { E::ni() }
#[doc = link_impls!["factors_proper_buf"]]
fn int_factors_proper_buf(self, fbuf: &mut [Self], upfbuf: &mut [Self])
-> Result<(usize, usize)> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_factors_proper_buf"]]
fn int_ref_factors_proper_buf(&self, fbuf: &mut [Self::Out], upfbuf: &mut [Self::Out])
-> Result<(usize, usize)> { E::ni() }
#[doc = link_impls!["factors_prime_buf"]]
fn int_factors_prime_buf(self, buffer: &mut [Self])
-> Result<usize> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_factors_prime_buf"]]
fn int_ref_factors_prime_buf(&self, buffer: &mut [Self::Out]) -> Result<usize> { E::ni() }
#[doc = link_impls!["factors_prime_unique_buf"]]
fn int_factors_prime_unique_buf(self, buffer: &mut [Self])
-> Result<usize> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_factors_prime_unique_buf"]]
fn int_ref_factors_prime_unique_buf(&self, buffer: &mut [Self::Out])
-> Result<usize> { E::ni() }
#[doc = link_impls!["is_prime"]]
fn int_is_prime(self) -> Result<bool> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_is_prime"]]
fn int_ref_is_prime(&self) -> Result<bool> { E::ni() }
#[doc = link_impls!["prime_nth"]]
fn int_prime_nth(self) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_prime_nth"]]
fn int_ref_prime_nth(&self) -> Result<Self::Out> { E::ni() }
#[doc = crate::_INT_NOTATION_PI!()]
#[doc = link_impls!["prime_pi"]]
fn int_prime_pi(self) -> Result<usize> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_prime_pi"]]
fn int_ref_prime_pi(&self) -> Result<usize> { E::ni() }
#[doc = link_impls!["totient"]]
fn int_totient(self) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_totient"]]
fn int_ref_totient(&self) -> Result<Self::Out> { E::ni() }
#[doc = crate::_INT_FORMULA_IS_SQUARE!()]
#[doc = link_impls!["is_square"]]
fn int_is_square(self) -> Result<bool> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_is_square"]]
fn int_ref_is_square(&self) -> Result<bool> { E::ni() }
#[doc = crate::_INT_ALGORITHM_SQRT_CEIL!()]
#[doc = link_impls!["sqrt_ceil"]]
fn int_sqrt_ceil(self) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_sqrt_ceil"]]
fn int_ref_sqrt_ceil(&self) -> Result<Self::Out> { E::ni() }
#[doc = crate::_INT_ALGORITHM_SQRT_FLOOR!()]
#[doc = link_impls!["sqrt_floor"]]
fn int_sqrt_floor(self) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_sqrt_floor"]]
fn int_ref_sqrt_floor(&self) -> Result<Self::Out> { E::ni() }
#[doc = crate::_INT_ALGORITHM_SQRT_ROUND!()]
#[doc = link_impls!["sqrt_round"]]
fn int_sqrt_round(self) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_sqrt_round"]]
fn int_ref_sqrt_round(&self) -> Result<Self::Out> { E::ni() }
#[doc = crate::_INT_FORMULA_ROOT_CEIL_SIGNED!()]
#[doc = link_impls!["root_ceil"]]
fn int_root_ceil(self, nth: u32) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_root_ceil"]]
fn int_ref_root_ceil(&self, nth: u32) -> Result<Self::Out> { E::ni() }
#[doc = crate::_INT_FORMULA_ROOT_FLOOR_SIGNED!()]
#[doc = link_impls!["root_floor"]]
fn int_root_floor(self, nth: u32) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_root_floor"]]
fn int_ref_root_floor(&self, nth: u32) -> Result<Self::Out> { E::ni() }
#[doc = link_impls!["modulo"]]
fn int_modulo(self, modulus: Self::Rhs) -> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_modulo"]]
fn int_ref_modulo(&self, modulus: &Self::Rhs) -> Result<Self::Out> { E::ni() }
#[doc = link_impls!["modulo_cycles"]]
fn int_modulo_cycles(self, modulus: Self::Rhs)
-> Result<ValueQuant<Self::Out, Self::Out>> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_modulo_cycles"]]
fn int_ref_modulo_cycles(&self, modulus: &Self::Rhs)
-> Result<ValueQuant<Self::Out, Self::Out>> where Self: Sized { E::ni() }
#[doc = link_impls!["modulo_add"]]
fn int_modulo_add(self, other: Self::Rhs, modulus: Self::Rhs)
-> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_modulo_add"]]
fn int_ref_modulo_add(&self, other: &Self::Rhs, modulus: &Self::Rhs)
-> Result<Self::Out> { E::ni() }
#[doc = link_impls!["modulo_add_cycles"]]
fn int_modulo_add_cycles(self, other: Self::Rhs, modulus: Self::Rhs)
-> Result<ValueQuant<Self::Out, Self::Out>> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_modulo_add_cycles"]]
fn int_ref_modulo_add_cycles(&self, other: &Self::Rhs, modulus: &Self::Rhs)
-> Result<ValueQuant<Self::Out, Self::Out>> where Self: Sized { E::ni() }
#[doc = link_impls!["modulo_add_inv"]]
fn int_modulo_add_inv(self, modulus: Self::Rhs)
-> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_modulo_add_inv"]]
fn int_ref_modulo_add_inv(&self, modulus: &Self::Rhs)
-> Result<Self::Out> { E::ni() }
#[doc = link_impls!["modulo_sub"]]
fn int_modulo_sub(self, other: Self::Rhs, modulus: Self::Rhs)
-> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_modulo_sub"]]
fn int_ref_modulo_sub(&self, other: &Self::Rhs, modulus: &Self::Rhs)
-> Result<Self::Out> { E::ni() }
#[doc = link_impls!["modulo_sub_cycles"]]
fn int_modulo_sub_cycles(self, other: Self::Rhs, modulus: Self::Rhs)
-> Result<ValueQuant<Self::Out, Self::Out>> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_modulo_sub_cycles"]]
fn int_ref_modulo_sub_cycles(&self, other: &Self::Rhs, modulus: &Self::Rhs)
-> Result<ValueQuant<Self::Out, Self::Out>> where Self: Sized { E::ni() }
#[doc = link_impls!["modulo_mul"]]
fn int_modulo_mul(self, other: Self::Rhs, modulus: Self::Rhs)
-> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_modulo_mul"]]
fn int_ref_modulo_mul(&self, other: &Self::Rhs, modulus: &Self::Rhs)
-> Result<Self::Out> { E::ni() }
#[doc = link_impls!["modulo_mul_cycles"]]
fn int_modulo_mul_cycles(self, other: Self::Rhs, modulus: Self::Rhs)
-> Result<ValueQuant<Self::Out, Self::Out>> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_modulo_mul_cycles"]]
fn int_ref_modulo_mul_cycles(&self, other: &Self::Rhs, modulus: &Self::Rhs)
-> Result<ValueQuant<Self::Out, Self::Out>> where Self: Sized { E::ni() }
#[doc = link_impls!["modulo_mul_inv"]]
fn int_modulo_mul_inv(self, modulus: Self::Rhs)
-> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_modulo_mul_inv"]]
fn int_ref_modulo_mul_inv(&self, modulus: &Self::Rhs)
-> Result<Self::Out> { E::ni() }
#[doc = link_impls!["modulo_div"]]
fn int_modulo_div(self, other: Self::Rhs, modulus: Self::Rhs)
-> Result<Self::Out> where Self: Sized { E::ni() }
#[doc = ref_fn!["int_modulo_div"]]
fn int_ref_modulo_div(&self, other: &Self::Rhs, modulus: &Self::Rhs)
-> Result<Self::Out> { E::ni() }
}
macro_rules! link_impls {
($fn:literal) => {
concat! {
"\n\n # Implementations\n\nSee an implementation for primitive integers: [`Int::`",
$fn, "][crate::Int::", $fn, "]." }
};
}
use link_impls;
macro_rules! ref_fn {
($fn:literal) => {
concat! { "Similar to [", $fn, "][Self::", $fn,
"], but operates on references instead of values." }
};
}
use ref_fn;