Expand description
Rational number struct with numerator, denominator and sign.
Fields
numer: u64Numerator
denom: u64Denominator
sign: i64Sign (-1 or +1)
Implementations
sourceimpl Ratio
impl Ratio
sourcepub fn prime_factors(&self) -> Vec<(u64, i64)>
pub fn prime_factors(&self) -> Vec<(u64, i64)>
Returns the prime factors with multiplicity of the ratio.
Examples
use padic::Ratio;
let r = Ratio::new(2, 15);
assert_eq!(r.prime_factors(), vec![(2, 1), (3, -1), (5, -1)]);sourcepub fn to_float(&self) -> f64
pub fn to_float(&self) -> f64
Returns the float representation of the ratio.
Examples
use padic::Ratio;
let r = Ratio::new(2, 4);
assert_eq!(r.to_float(), 0.5);sourcepub fn to_string(&self) -> String
pub fn to_string(&self) -> String
Returns the string representation of the ratio.
Examples
use padic::Ratio;
let r = Ratio::new(2, -4);
assert_eq!(r.to_string(), "-1/2");sourcepub fn padic_valuation(&self, prime: u64) -> i64
pub fn padic_valuation(&self, prime: u64) -> i64
Returns the p-adic valuation of the ratio.
Examples
use padic::Ratio;
let r = Ratio::new(71, 9);
assert_eq!(r.padic_valuation(3), -2);sourcepub fn padic_absolute(&self, prime: u64) -> Ratio
pub fn padic_absolute(&self, prime: u64) -> Ratio
Returns the p-adic absolute value of the ratio.
Examples
use padic::Ratio;
let r = Ratio::new(71, 9);
assert_eq!(r.padic_absolute(3), Ratio::new(9, 1));sourcepub fn to_padic(&self, prime: u64, precision: u64) -> Padic
pub fn to_padic(&self, prime: u64, precision: u64) -> Padic
Convert the ratio into a p-adic number.
Info: https://math.stackexchange.com/a/1187037
Arguments
prime- A prime number.precision- A positive integer.
Examples
3-adic expansion of 2/5 with precision of 5 -> 1,1,2,1,0
- +2/5 = 1 - 3 * 1/5
- -1/5 = 1 - 3 * 2/5
- -2/5 = 2 - 3 * 4/5
- -4/5 = 1 - 3 * 3/5
- -3/5 = 0 - 3 * 1/5
use padic::Ratio;
let r = Ratio::new(2, 5);
let p = r.to_padic(3, 5);
assert_eq!(p.expansion, vec![1, 1, 2, 1, 0]);Trait Implementations
impl StructuralPartialEq for Ratio
Auto Trait Implementations
impl RefUnwindSafe for Ratio
impl Send for Ratio
impl Sync for Ratio
impl Unpin for Ratio
impl UnwindSafe for Ratio
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more