diff --git a/src/uu/factor/src/miller_rabin.rs b/src/uu/factor/src/miller_rabin.rs index b5a01735a..8906abf59 100644 --- a/src/uu/factor/src/miller_rabin.rs +++ b/src/uu/factor/src/miller_rabin.rs @@ -69,7 +69,7 @@ pub(crate) fn test(m: A) -> Result { continue; } - let a = m.from_u64(_a); + let a = m.to_mod(_a); // x = a^r mod n let mut x = m.pow(a, r); diff --git a/src/uu/factor/src/numeric/montgomery.rs b/src/uu/factor/src/numeric/montgomery.rs index 504e6a09b..2a6782a02 100644 --- a/src/uu/factor/src/numeric/montgomery.rs +++ b/src/uu/factor/src/numeric/montgomery.rs @@ -16,7 +16,7 @@ pub(crate) trait Arithmetic: Copy + Sized { fn new(m: u64) -> Self; fn modulus(&self) -> u64; - fn from_u64(&self, n: u64) -> Self::ModInt; + fn to_mod(&self, n: u64) -> Self::ModInt; fn to_u64(&self, n: Self::ModInt) -> u64; fn add(&self, a: Self::ModInt, b: Self::ModInt) -> Self::ModInt; fn mul(&self, a: Self::ModInt, b: Self::ModInt) -> Self::ModInt; @@ -47,13 +47,13 @@ pub(crate) trait Arithmetic: Copy + Sized { } fn one(&self) -> Self::ModInt { - self.from_u64(1) + self.to_mod(1) } fn minus_one(&self) -> Self::ModInt { - self.from_u64(self.modulus() - 1) + self.to_mod(self.modulus() - 1) } fn zero(&self) -> Self::ModInt { - self.from_u64(0) + self.to_mod(0) } } @@ -113,7 +113,7 @@ impl Arithmetic for Montgomery { self.n.as_u64() } - fn from_u64(&self, x: u64) -> Self::ModInt { + fn to_mod(&self, x: u64) -> Self::ModInt { // TODO: optimise! debug_assert!(x < self.n.as_u64()); let r = T::from_double_width( @@ -189,9 +189,9 @@ mod tests { let n = 2 * n + 1; let m = Montgomery::::new(n); for x in 0..n { - let m_x = m.from_u64(x); + let m_x = m.to_mod(x); for y in 0..=x { - let m_y = m.from_u64(y); + let m_y = m.to_mod(y); println!("{n:?}, {x:?}, {y:?}", n = n, x = x, y = y); assert_eq!((x + y) % n, m.to_u64(m.add(m_x, m_y))); } @@ -205,9 +205,9 @@ mod tests { let n = 2 * n + 1; let m = Montgomery::::new(n); for x in 0..n { - let m_x = m.from_u64(x); + let m_x = m.to_mod(x); for y in 0..=x { - let m_y = m.from_u64(y); + let m_y = m.to_mod(y); assert_eq!((x * y) % n, m.to_u64(m.mul(m_x, m_y))); } } @@ -220,7 +220,7 @@ mod tests { let n = 2 * n + 1; let m = Montgomery::::new(n); for x in 0..n { - let x_ = m.from_u64(x); + let x_ = m.to_mod(x); assert_eq!(x, m.to_u64(x_)); } } diff --git a/src/uu/factor/src/rho.rs b/src/uu/factor/src/rho.rs index b28e88e91..e7aa00b4d 100644 --- a/src/uu/factor/src/rho.rs +++ b/src/uu/factor/src/rho.rs @@ -18,7 +18,7 @@ pub(crate) fn find_divisor(n: A) -> u64 { let mut rand = { let range = Uniform::new(1, n.modulus()); let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap(); - move || n.from_u64(range.sample(&mut rng)) + move || n.to_mod(range.sample(&mut rng)) }; let quadratic = |a, b| move |x| n.add(n.mul(a, n.mul(x, x)), b); diff --git a/src/uucore/src/lib/features/tokenize/num_format/formatters/base_conv/mod.rs b/src/uucore/src/lib/features/tokenize/num_format/formatters/base_conv/mod.rs index e6b1ea770..3df9f7129 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/formatters/base_conv/mod.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/formatters/base_conv/mod.rs @@ -179,7 +179,7 @@ pub fn str_to_arrnum(src: &str, radix_def_src: &dyn RadixDef) -> Vec { let mut intermed_in: Vec = Vec::new(); for c in src.chars() { #[allow(clippy::single_match)] - match radix_def_src.from_char(c) { + match radix_def_src.parse_char(c) { Some(u) => { intermed_in.push(u); } @@ -193,7 +193,7 @@ pub fn arrnum_to_str(src: &[u8], radix_def_dest: &dyn RadixDef) -> String { let mut str_out = String::new(); for u in src.iter() { #[allow(clippy::single_match)] - match radix_def_dest.from_u8(*u) { + match radix_def_dest.format_u8(*u) { Some(c) => { str_out.push(c); } @@ -219,8 +219,8 @@ pub fn base_conv_str( pub trait RadixDef { fn get_max(&self) -> u8; - fn from_char(&self, x: char) -> Option; - fn from_u8(&self, x: u8) -> Option; + fn parse_char(&self, x: char) -> Option; + fn format_u8(&self, x: u8) -> Option; } pub struct RadixTen; @@ -232,13 +232,13 @@ impl RadixDef for RadixTen { fn get_max(&self) -> u8 { 10 } - fn from_char(&self, c: char) -> Option { + fn parse_char(&self, c: char) -> Option { match c { '0'..='9' => Some(c as u8 - ZERO_ASC), _ => None, } } - fn from_u8(&self, u: u8) -> Option { + fn format_u8(&self, u: u8) -> Option { match u { 0..=9 => Some((ZERO_ASC + u) as char), _ => None, @@ -250,7 +250,7 @@ impl RadixDef for RadixHex { fn get_max(&self) -> u8 { 16 } - fn from_char(&self, c: char) -> Option { + fn parse_char(&self, c: char) -> Option { match c { '0'..='9' => Some(c as u8 - ZERO_ASC), 'A'..='F' => Some(c as u8 + 10 - UPPER_A_ASC), @@ -258,7 +258,7 @@ impl RadixDef for RadixHex { _ => None, } } - fn from_u8(&self, u: u8) -> Option { + fn format_u8(&self, u: u8) -> Option { match u { 0..=9 => Some((ZERO_ASC + u) as char), 10..=15 => Some((UPPER_A_ASC + (u - 10)) as char),