Remove unused gcd functions
All checks were successful
timw4mail/rusty-numbers/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2021-06-03 18:23:02 -04:00
parent 4ac159c603
commit be85f4acca
3 changed files with 3 additions and 36 deletions

View File

@ -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;

View File

@ -16,4 +16,3 @@ extern crate std;
pub mod bigint;
pub mod num;
pub mod rational;

View File

@ -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]