Skip to main content

CanApproximate

Trait CanApproximate 

Source
pub trait CanApproximate: HasDigits {
    type Approximation: HasApproximateDigits;

    // Required methods
    fn approximation(&self, n: Self::DigitIndex) -> Self::Approximation;
    fn into_approximation(self, n: Self::DigitIndex) -> Self::Approximation;
}
Expand description

Can be approximated into Approximate

Required Associated Types§

Source

type Approximation: HasApproximateDigits

Output of the approximation

Required Methods§

Source

fn approximation(&self, n: Self::DigitIndex) -> Self::Approximation

Approximate an number expansion to digit index n. See also: into_approximation

let u = UAdic::new(5, vec![1, 3, 2, 1, 2, 1, 2]);
let z = ZAdic::new_approx(5, 9, vec![1, 3, 2, 1, 2, 1, 2, 0, 0]);
let zs = ZAdic::new_approx(5, 5, vec![1, 3, 2, 1, 2]);
assert_eq!(z, u.approximation(9));
assert_eq!(zs, u.approximation(5));
assert_eq!(zs, z.approximation(5));
assert_eq!(zs, zs.approximation(9));
let r = EAdic::new_repeating(5, vec![1, 3], vec![2, 1]);
assert_eq!(zs, r.approximation(5));

let q = QAdic::new(UAdic::new(5, vec![1, 3, 2, 1, 2, 1, 2]), -5);
let z = QAdic::new(ZAdic::new_approx(5, 9, vec![1, 3, 2, 1, 2, 1, 2, 0, 0]), -5);
let zs = QAdic::new(ZAdic::new_approx(5, 6, vec![1, 3, 2, 1, 2, 1]), -5);
assert_eq!(z, q.approximation(4));
assert_eq!(zs, q.approximation(1));
let qr = QAdic::new(EAdic::new_repeating(5, vec![1, 3], vec![2, 1]), -5);
assert_eq!(zs, qr.approximation(1));
Source

fn into_approximation(self, n: Self::DigitIndex) -> Self::Approximation

Consume and get the approximation to digit index n. See also: approximation

let u = UAdic::new(5, vec![1, 3, 2, 1, 2, 1, 2]);
let z = ZAdic::new_approx(5, 9, vec![1, 3, 2, 1, 2, 1, 2, 0, 0]);
let zs = ZAdic::new_approx(5, 5, vec![1, 3, 2, 1, 2]);
assert_eq!(z, u.clone().into_approximation(9));
assert_eq!(zs, u.clone().into_approximation(5));
assert_eq!(zs, z.clone().into_approximation(5));
assert_eq!(zs, zs.clone().into_approximation(9));
let r = EAdic::new_repeating(5, vec![1, 3], vec![2, 1]);
assert_eq!(zs, r.into_approximation(5));

let q = QAdic::new(UAdic::new(5, vec![1, 3, 2, 1, 2, 1, 2]), -5);
let z = QAdic::new(ZAdic::new_approx(5, 9, vec![1, 3, 2, 1, 2, 1, 2, 0, 0]), -5);
let zs = QAdic::new(ZAdic::new_approx(5, 6, vec![1, 3, 2, 1, 2, 1]), -5);
assert_eq!(z, q.clone().into_approximation(4));
assert_eq!(zs, q.clone().into_approximation(1));
let qr = QAdic::new(EAdic::new_repeating(5, vec![1, 3], vec![2, 1]), -5);
assert_eq!(zs, qr.into_approximation(1));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§