Struct oxygen_quark::fraction::Fraction
source · Fields§
§numerator: i64
The numerator
denominator: i64
The denominator
Implementations§
source§impl Fraction
impl Fraction
sourcepub fn new(numerator: i64, denominator: i64) -> Fraction
pub fn new(numerator: i64, denominator: i64) -> Fraction
Generates a new Fraction
It returns a Fraction
in its fully reduced form,
after calculating the greatest common divisor.
Panics
Panics if denominator
is zero (0).
sourcepub fn new_from_decimal(decimal: f64) -> Fraction
pub fn new_from_decimal(decimal: f64) -> Fraction
Generates a new Fraction
from an f64
It returns a Fraction
in its fully reduced form,
after calculating the greatest common divisor.
Useful for when calculating square-roots, sine, cosine, tangent functions and more.
Panics
Panics if the numerator is too large, ‘attempt to multiply with overflow’.
sourcepub fn greatest_common_divisor(numerator: i64, denominator: i64) -> i64
pub fn greatest_common_divisor(numerator: i64, denominator: i64) -> i64
Returns the greatest common divisor, as an i64
.
Examples
let n1 = 50;
let n2 = 20;
// Prints out "10"
println!("{}", Fraction::greatest_common_divisor(n1, n2));
sourcepub fn reciprocal(self) -> Fraction
pub fn reciprocal(self) -> Fraction
Returns the reciprocal of the Fraction
it’s called on.
Just moves the denominator to the numerator position and vice versa.
Panics
Panics when being called on a Fraction
with numerator 0.
sourcepub fn cosine(self) -> Fraction
pub fn cosine(self) -> Fraction
Returns an approximated Fraction
of the cosine (cos) of the Fraction
sourcepub fn arc_cosine(self) -> Fraction
pub fn arc_cosine(self) -> Fraction
Returns an approximated Fraction
of the arc cosine (cos^-1) of the Fraction
sourcepub fn sine(self) -> Fraction
pub fn sine(self) -> Fraction
Returns an approximated Fraction
of the sine (sin) of the Fraction
sourcepub fn arc_sine(self) -> Fraction
pub fn arc_sine(self) -> Fraction
Returns an approximated Fraction
of the arc sine (sin^-1) of the Fraction
sourcepub fn tangent(self) -> Fraction
pub fn tangent(self) -> Fraction
Returns an approximated Fraction
of the tangent (tan) of the Fraction
sourcepub fn arc_tangent(self) -> Fraction
pub fn arc_tangent(self) -> Fraction
Returns an approximated Fraction
of the arc tangent (tan^-1) of the Fraction
Trait Implementations§
source§impl AddAssign<Fraction> for Fraction
impl AddAssign<Fraction> for Fraction
source§fn add_assign(&mut self, other: Fraction)
fn add_assign(&mut self, other: Fraction)
+=
operation. Read moresource§impl DivAssign<Fraction> for Fraction
impl DivAssign<Fraction> for Fraction
source§fn div_assign(&mut self, other: Fraction)
fn div_assign(&mut self, other: Fraction)
/=
operation. Read moresource§impl MulAssign<Fraction> for Fraction
impl MulAssign<Fraction> for Fraction
source§fn mul_assign(&mut self, other: Fraction)
fn mul_assign(&mut self, other: Fraction)
*=
operation. Read moresource§impl Ord for Fraction
impl Ord for Fraction
source§impl PartialOrd<Fraction> for Fraction
impl PartialOrd<Fraction> for Fraction
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl SubAssign<Fraction> for Fraction
impl SubAssign<Fraction> for Fraction
source§fn sub_assign(&mut self, other: Fraction)
fn sub_assign(&mut self, other: Fraction)
-=
operation. Read more