Struct calcu_rs::rational::Rational

source ·
pub struct Rational(pub(crate) Ratio<Int>);

Tuple Fields§

§0: Ratio<Int>

Implementations§

source§

impl Rational

source

pub const MINUS_TWO: Self = _

source

pub const MINUS_ONE: Self = _

source

pub const ZERO: Self = _

source

pub const ONE: Self = _

source

pub const TWO: Self = _

source

const fn new_raw(n: Int, d: Int) -> Self

source

pub fn new(n: impl Into<Int>, d: impl Into<Int>) -> Self

source

pub const fn new_int(n: Int) -> Self

source

pub const fn numer(&self) -> Int

source

pub fn to_int(&self) -> Option<Int>

source

pub fn f64_approx(&self) -> f64

source

pub const fn denom(&self) -> Int

source

pub fn is_min_two(&self) -> bool

source

pub fn is_min_one(&self) -> bool

source

pub fn is_zero(&self) -> bool

source

pub fn is_one(&self) -> bool

source

pub fn is_two(&self) -> bool

source

pub fn is_pos(&self) -> bool

source

pub fn is_neg(&self) -> bool

source

pub fn is_int(&self) -> bool

source

pub fn is_fraction(&self) -> bool

source

pub fn is_even(&self) -> bool

source

pub fn is_odd(&self) -> bool

source

pub fn inverse(self) -> Option<Self>

none if self is zero

source

pub fn abs(self) -> Self

source

pub fn floor(self) -> Int

source

pub fn div_rem(&self) -> (Self, Self)

source

pub fn pow(self, rhs: Self) -> (Self, Self)

will calculate self to the power of an integer number.

if the exponent is (a/b) non-int: we calculate the power to the int quotient of a/b and return the remainder: (self^quot, rem).

n^(a/b) = n^(quot + rem) = n^(quot) * n^(rem) -> (n^quot, rem)

quot: Int, rest: Fraction, n^(quot): Rational

returns the input if calculation was not possible

source

pub fn pow_basic(self, rhs: Self) -> Option<Self>

source

pub fn int_gcd(&self, rhs: &Self) -> Option<Rational>

Trait Implementations§

source§

impl Add<&Rational> for Rational

source§

type Output = Rational

The resulting type after applying the + operator.
source§

fn add(self, rhs: &Self) -> Self::Output

Performs the + operation. Read more
source§

impl Add for Rational

source§

type Output = Rational

The resulting type after applying the + operator.
source§

fn add(self, rhs: Rational) -> Rational

Performs the + operation. Read more
source§

impl AddAssign<&Rational> for Rational

source§

fn add_assign(&mut self, rhs: &Self)

Performs the += operation. Read more
source§

impl AddAssign for Rational

source§

fn add_assign(&mut self, rhs: Rational)

Performs the += operation. Read more
source§

impl Clone for Rational

source§

fn clone(&self) -> Rational

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Rational

source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Rational

source§

fn default() -> Rational

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Rational

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Rational

source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Div<&Rational> for Rational

source§

type Output = Rational

The resulting type after applying the / operator.
source§

fn div(self, rhs: &Self) -> Self::Output

Performs the / operation. Read more
source§

impl Div for Rational

source§

type Output = Rational

The resulting type after applying the / operator.
source§

fn div(self, rhs: Rational) -> Rational

Performs the / operation. Read more
source§

impl DivAssign<&Rational> for Rational

source§

fn div_assign(&mut self, rhs: &Self)

Performs the /= operation. Read more
source§

impl DivAssign for Rational

source§

fn div_assign(&mut self, rhs: Rational)

Performs the /= operation. Read more
source§

impl From<(i128, i128)> for Rational

source§

fn from(value: (i128, i128)) -> Self

Converts to this type from the input type.
source§

impl From<(i32, i32)> for Rational

source§

fn from(value: (i32, i32)) -> Self

Converts to this type from the input type.
source§

impl From<Rational> for Atom

source§

fn from(value: Rational) -> Self

Converts to this type from the input type.
source§

impl From<Rational> for Real

source§

fn from(value: Rational) -> Self

Converts to this type from the input type.
source§

impl From<i128> for Rational

source§

fn from(value: i128) -> Self

Converts to this type from the input type.
source§

impl From<i32> for Rational

source§

fn from(value: i32) -> Self

Converts to this type from the input type.
source§

impl From<i64> for Rational

source§

fn from(value: i64) -> Self

Converts to this type from the input type.
source§

impl From<u32> for Rational

source§

fn from(value: u32) -> Self

Converts to this type from the input type.
source§

impl From<u64> for Rational

source§

fn from(value: u64) -> Self

Converts to this type from the input type.
source§

impl Hash for Rational

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Mul<&Rational> for Rational

source§

type Output = Rational

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &Self) -> Self::Output

Performs the * operation. Read more
source§

impl Mul for Rational

source§

type Output = Rational

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Rational) -> Rational

Performs the * operation. Read more
source§

impl MulAssign<&Rational> for Rational

source§

fn mul_assign(&mut self, rhs: &Self)

Performs the *= operation. Read more
source§

impl MulAssign for Rational

source§

fn mul_assign(&mut self, rhs: Rational)

Performs the *= operation. Read more
source§

impl Ord for Rational

source§

fn cmp(&self, other: &Rational) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Rational

source§

fn eq(&self, other: &Rational) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Rational

source§

fn partial_cmp(&self, other: &Rational) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Rational

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Sub<&Rational> for Rational

source§

type Output = Rational

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &Self) -> Self::Output

Performs the - operation. Read more
source§

impl Sub for Rational

source§

type Output = Rational

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Rational) -> Rational

Performs the - operation. Read more
source§

impl SubAssign<&Rational> for Rational

source§

fn sub_assign(&mut self, rhs: &Self)

Performs the -= operation. Read more
source§

impl SubAssign for Rational

source§

fn sub_assign(&mut self, rhs: Rational)

Performs the -= operation. Read more
source§

impl SymbolicExpr for Rational

source§

fn reduce(&self) -> Expr

basic simplification that can be applied regardless of context Read more
source§

fn is_atom(&self) -> bool

source§

fn n_args(&self) -> usize

source§

fn args(&self) -> &[Expr]

source§

fn args_mut(&mut self) -> &mut [Expr]

source§

fn iter_args(&self) -> impl Iterator<Item = &Expr>

source§

fn map_args(self, map_fn: impl Fn(&mut Expr)) -> Self

source§

impl Copy for Rational

source§

impl Eq for Rational

source§

impl StructuralPartialEq for Rational

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,