rational: add From<(i32, i32)> for Rational
This commit is contained in:
parent
a282d85662
commit
2baf1deaab
@ -73,18 +73,6 @@ impl Into<AVRational> for Rational {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Rational {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
|
||||||
f.write_str(&format!("{}/{}", self.numerator(), self.denominator()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for Rational {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
|
||||||
f.write_str(&format!("Rational({}/{})", self.numerator(), self.denominator()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<f64> for Rational {
|
impl From<f64> for Rational {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(value: f64) -> Rational {
|
fn from(value: f64) -> Rational {
|
||||||
@ -112,6 +100,12 @@ impl From<Rational> for u32 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<(i32, i32)> for Rational {
|
||||||
|
fn from((num, den): (i32, i32)) -> Rational {
|
||||||
|
Rational::new(num, den)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl PartialEq for Rational {
|
impl PartialEq for Rational {
|
||||||
fn eq(&self, other: &Rational) -> bool {
|
fn eq(&self, other: &Rational) -> bool {
|
||||||
if self.0 == other.0 && self.1 == other.1 {
|
if self.0 == other.0 && self.1 == other.1 {
|
||||||
@ -190,6 +184,18 @@ impl Div for Rational {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Rational {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
|
f.write_str(&format!("{}/{}", self.numerator(), self.denominator()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for Rational {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
|
f.write_str(&format!("Rational({}/{})", self.numerator(), self.denominator()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn nearer(q: Rational, q1: Rational, q2: Rational) -> Ordering {
|
pub fn nearer(q: Rational, q1: Rational, q2: Rational) -> Ordering {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user