From be85f4acca31b37f066b7a6b226b1cb12936aee4 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Thu, 3 Jun 2021 18:23:02 -0400 Subject: [PATCH] Remove unused gcd functions --- src/bigint.rs | 2 +- src/lib.rs | 1 - src/num.rs | 36 ++---------------------------------- 3 files changed, 3 insertions(+), 36 deletions(-) diff --git a/src/bigint.rs b/src/bigint.rs index 255b70b..3e5f35f 100644 --- a/src/bigint.rs +++ b/src/bigint.rs @@ -1,7 +1,7 @@ #![allow(unused_variables)] //! \[WIP\] Arbitrarily large integers use crate::num::FracOp; -use crate::num::Sign::{self, Positive, Negative}; +use crate::num::Sign::{self, Negative, Positive}; #[cfg(all(feature = "alloc", not(feature = "std")))] extern crate alloc; diff --git a/src/lib.rs b/src/lib.rs index 83e8c31..91282c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,4 +16,3 @@ extern crate std; pub mod bigint; pub mod num; pub mod rational; - diff --git a/src/num.rs b/src/num.rs index 81f90e0..6a27fef 100644 --- a/src/num.rs +++ b/src/num.rs @@ -2,7 +2,8 @@ //! //! Home to the numeric trait chain of doom, aka `Unsigned` #![allow(unused_comparisons)] -use core::cmp::{max, min, Ordering}; + +use core::cmp::Ordering; use core::convert::TryFrom; use core::fmt::Debug; use core::ops::{ @@ -143,12 +144,6 @@ pub trait Unsigned: /// Find the greatest common denominator of two numbers fn gcd(a: Self, b: Self) -> Self; - /// Euclid gcd algorithm - fn e_gcd(a: Self, b: Self) -> Self; - - /// Stein gcd algorithm - fn stein_gcd(a: Self, b: Self) -> Self; - /// Find the least common multiple of two numbers fn lcm(a: Self, b: Self) -> Self; } @@ -246,31 +241,6 @@ macro_rules! impl_unsigned { Self::gcd((b - a) >> 1, a) } - fn e_gcd(x: $Type, y: $Type) -> $Type { - let mut x = x; - let mut y = y; - while y != 0 { - let t = y; - y = x % y; - x = t; - } - x - } - - fn stein_gcd(a: Self, b: Self) -> Self { - match ((a, b), (a & 1, b & 1)) { - ((x, y), _) if x == y => y, - ((0, x), _) | ((x, 0), _) => x, - ((x, y), (0, 1)) | ((y, x), (1, 0)) => Self::stein_gcd(x >> 1, y), - ((x, y), (0, 0)) => Self::stein_gcd(x >> 1, y >> 1) << 1, - ((x, y), (1, 1)) => { - let (x, y) = (min(x, y), max(x, y)); - Self::stein_gcd((y - x) >> 1, x) - } - _ => unreachable!(), - } - } - fn lcm(a: $Type, b: $Type) -> $Type { if (a == 0 && b == 0) { return 0; @@ -344,8 +314,6 @@ mod tests { assert_eq!(u8::gcd(2, 2), 2); assert_eq!(u8::gcd(2, 8), 2); assert_eq!(u16::gcd(36, 48), 12); - assert_eq!(u16::e_gcd(36, 48), 12); - assert_eq!(u16::stein_gcd(36, 48), 12); } #[test]