pub struct Ratio {
    pub numer: u64,
    pub denom: u64,
    pub sign: i64,
}
Expand description

Rational number struct with numerator, denominator and sign.

Fields

numer: u64

Numerator

denom: u64

Denominator

sign: i64

Sign (-1 or +1)

Implementations

Returns a ratio with numerator and denominator reduced to lowest terms.

Arguments
  • num - A signed integer numerator.
  • denom - A signed integer denominator.
Example
use padic::Ratio;
let r = Ratio::new(2, 4);
assert_eq!(r.num, 1);

Returns the sum of two rational numbers

Arguments
  • b - Another ratio.
Examples
use padic::Ratio;
let a = Ratio::new(-2, 5);
let b = Ratio::new(3, 5);
assert_eq!(a.add(b), Ratio::new(1, 5));

Returns the multiplication of two rational numbers

Arguments
  • b - Another ratio.
Examples
use padic::Ratio;
let a = Ratio::new(-2, 5);
let b = Ratio::new(3, 5);
assert_eq!(a.mul(b), Ratio::new(-6, 25));

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)]);

Returns the float representation of the ratio.

Examples
use padic::Ratio;
let r = Ratio::new(2, 4);
assert_eq!(r.to_float(), 0.5);

Returns the string representation of the ratio.

Examples
use padic::Ratio;
let r = Ratio::new(2, -4);
assert_eq!(r.to_string(), "-1/2");

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

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

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]);

Returns the next digit of the p-adic expansion.

Arguments
  • prime - A prime number.
use padic::Ratio;
let a = Ratio::new(2, 5);
assert_eq!(a.next_digit(3), (1, Ratio::new(-1, 5)));

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.