use crate::integer::debug_fmpz;
use flint3_sys::{fmpz_mod_ctx, nmod_t};
use std::{fmt, rc::Rc};
mod cmp;
mod distance;
mod fmpz_helpers;
mod from;
mod get;
mod ownership;
mod properties;
mod serialize;
mod to_string;
mod unsafe_functions;
pub struct Modulus {
pub(crate) modulus: Rc<fmpz_mod_ctx>,
}
impl fmt::Debug for Modulus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Modulus {{ modulus: {}, storage: {{ modulus: {}}}}}",
self,
debug_fmpz_mod_ctx(&self.modulus)
)
}
}
macro_rules! debug_fn_ptr {
($opt_fn:expr) => {
match $opt_fn {
Some(f) => format!("Some({:#x})", f as usize),
None => "None".to_string(),
}
};
}
fn debug_fmpz_mod_ctx(value: &fmpz_mod_ctx) -> String {
format!(
"fmpz_mod_ctx {{ n: [{}], add_fxn: {}, sub_fxn: {}, mul_fxn: {}, mod_: {}, n_limbs: {:?}, ninv_limbs: {:?}}}",
debug_fmpz(&value.n[0]),
debug_fn_ptr!(value.add_fxn),
debug_fn_ptr!(value.sub_fxn),
debug_fn_ptr!(value.mul_fxn),
debug_nmod_t(&value.mod_),
value.n_limbs,
value.ninv_limbs
)
}
fn debug_nmod_t(value: &nmod_t) -> String {
format!(
"nmod_t {{ n: {}, ninv: {}, norm: {} }}",
value.n, value.ninv, value.norm
)
}