addition: Fraction pending implementations
This commit is contained in:
102
src/lib.rs
102
src/lib.rs
@@ -1,3 +1,5 @@
|
|||||||
|
use std::{fmt, ops};
|
||||||
|
|
||||||
pub struct Fraction {
|
pub struct Fraction {
|
||||||
num: i64,
|
num: i64,
|
||||||
den: i64,
|
den: i64,
|
||||||
@@ -10,7 +12,7 @@ pub enum FractionError {
|
|||||||
Overflow,
|
Overflow,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for FractionError {
|
impl fmt::Display for FractionError {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
FractionError::DivisionByZero => write!(f, "Division by zero"),
|
FractionError::DivisionByZero => write!(f, "Division by zero"),
|
||||||
@@ -30,6 +32,104 @@ impl Fraction {
|
|||||||
|
|
||||||
Ok(Fraction { num, den })
|
Ok(Fraction { num, den })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn reciprocal(&self) -> Result<Self, FractionError> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn abs(&self) -> Self {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_zero(&self) -> bool {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_integer(&self) -> bool {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gcd(a: i64, b: i64) -> i64 {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reduce(&mut self) {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ops::Mul for Fraction {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn mul(self, rhs: Self) -> Self::Output {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ops::Add for Fraction {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn add(self, rhs: Self) -> Self::Output {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ops::Div for Fraction {
|
||||||
|
type Output = Result<Self, FractionError>;
|
||||||
|
|
||||||
|
fn div(self, rhs: Self) -> Self::Output {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ops::Sub for Fraction {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn sub(self, rhs: Self) -> Self::Output {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ops::Neg for Fraction {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn neg(self) -> Self::Output {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Fraction {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<i32> for Fraction {
|
||||||
|
fn from(value: i32) -> Self {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<i64> for Fraction {
|
||||||
|
fn from(value: i64) -> Self {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<(i32, i32)> for Fraction {
|
||||||
|
type Error = FractionError;
|
||||||
|
|
||||||
|
fn try_from(value: (i32, i32)) -> Result<Self, Self::Error> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<(i64, i64)> for Fraction {
|
||||||
|
type Error = FractionError;
|
||||||
|
|
||||||
|
fn try_from(value: (i64, i64)) -> Result<Self, Self::Error> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
Reference in New Issue
Block a user