Struct Integer

Source
pub struct Integer {
    pub sign: bool,
    /* private fields */
}
Expand description

Integer type with no size limit.

Fields§

§sign: bool

Sign of the number.

Implementations§

Source§

impl Integer

Source

pub fn of(sign: bool, digits: &[u8]) -> Option<Self>

Construct an integer by passing the sign and each digit.

§Example
use rmatrix_ks::number::instances::integer::Integer;

let digits = vec![1, 2, 3];
// Integer(123)
let Some(_) = Integer::of(true, &digits) else {
    unreachable!();
};
§Warning

Each digit should be between [0, 9], which means it is a single decimal digit.

use rmatrix_ks::number::instances::integer::Integer;

let digits = vec![1, 2, 10];
assert_eq!(Integer::of(true, &digits), None);
Source

pub fn of_str(integer_number: &str) -> Option<Self>

Construct integer numbers from string.

§Examples
use rmatrix_ks::number::instances::integer::Integer;

let i1 = Integer::of_str("-123456");
let i2 = Integer::of(false, &[1, 2, 3, 4, 5, 6]);
assert_eq!(i1, i2);
Source

pub fn digits(&self) -> Vec<u8>

Return the digit at each position.

§Examples
use rmatrix_ks::number::instances::integer::Integer;

let digits = Integer::of_str("-123456").map(|e| e.digits());
assert_eq!(digits, Some(vec![1, 2, 3, 4, 5, 6]));

Trait Implementations§

Source§

impl Add for Integer

Implement the addition operation for the integer number.

Source§

type Output = Integer

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Clone for Integer

Source§

fn clone(&self) -> Integer

Returns a duplicate 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 Integer

Implement Debug for Integer.

Source§

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

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

impl Default for Integer

Implement Default for the integer number.

Source§

fn default() -> Self

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

impl Display for Integer

Implement Display for Integer.

Source§

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

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

impl FromStr for Integer

Implement FromStr for Integer.

Source§

type Err = ()

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Integral for Integer

Implement the concept of Integral for Integer.

Source§

fn quot_rem(self, rhs: Self) -> (Self, Self)

Calculating the quotient and remainder of two integers, where the quotient is rounded towards zero. Read more
Source§

fn div_mod(self, rhs: Self) -> (Self, Self)

Calculating the division and modulus of two integers, where the division result is rounded towards negative infinity. Read more
Source§

fn to_integer(self) -> Integer

Convert the integral number to an integer.
Source§

fn quotient(self, rhs: Self) -> Self

Calculating the quotient of two integers, rounding the result towards zero.
Source§

fn remainder(self, rhs: Self) -> Self

Calculating the remainder corresponding to the quotient rounded towards zero.
Source§

fn division(self, rhs: Self) -> Self

Calculating the quotient of two integers, rounding the result towards negative infinity.
Source§

fn modulus(self, rhs: Self) -> Self

Calculating the modulus of two integers.
Source§

fn is_even(&self) -> bool

Validate whether an integral number is even.
Source§

fn is_odd(&self) -> bool

Validate whether an integral number is odd.
Source§

impl Mul for Integer

Implement the multiplication operation for the integer number.

Source§

type Output = Integer

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Neg for Integer

Implement the negation operation for the integer number.

Source§

type Output = Integer

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl Number for Integer

Implement the concept of NUMBER for the integer number.

Source§

fn absolute_value(&self) -> Self

Calculate the absolute value of a number.
Source§

fn sign_number(&self) -> Self

Calculate the sign of a number.
Source§

fn from_integer(integer_number: Integer) -> Self

Convert an integer to another numeric type.
Source§

impl One for Integer

Source§

fn is_one(&self) -> bool

Validate whether an integer is one.

§Examples
use rmatrix_ks::number::{instances::integer::Integer, traits::one::One};

let a = Integer::one();
assert!(a.is_one());
let b = Integer::of(true, &[1, 6]);
assert!(b.is_some_and(|e| !e.is_one()));
Source§

fn one() -> Self

Return the ONE number.
Source§

impl Ord for Integer

Implement Ord for the integer number.

Source§

fn cmp(&self, other: &Self) -> 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,

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

impl PartialEq for Integer

Source§

fn eq(&self, other: &Integer) -> 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 Integer

Implement PartialOrd for the integer number.

Source§

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

Compare two integers.

§Examples
use rmatrix_ks::number::instances::integer::Integer;

// 512
let a = Integer::of(true, &[5, 1, 2]).unwrap();
// 512
let another_a = Integer::of(true, &[5, 1, 2]).unwrap();
// -128
let b = Integer::of(false, &[1, 2, 8]).unwrap();
// 1024
let c = Integer::of(true, &[1, 0, 2, 4]).unwrap();
assert_eq!(a.partial_cmp(&another_a), Some(std::cmp::Ordering::Equal));
assert_eq!(a.partial_cmp(&b), Some(std::cmp::Ordering::Greater));
assert_eq!(a.partial_cmp(&c), Some(std::cmp::Ordering::Less));
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 Real for Integer

Implement the concept of Real for Integer.

Source§

fn to_rational(self) -> Rational

Convert a real number to a rational number.
Source§

impl Sub for Integer

Implement the subtraction operation for the integer number.

Source§

type Output = Integer

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Zero for Integer

Implement the concept of ZERO for the integer number.

Source§

fn zero() -> Self

Retrieve zeros in integers.

§Examples
use rmatrix_ks::number::{instances::integer::Integer, traits::zero::Zero};

let a = Integer::zero();
let Some(zero) = Integer::of_str("0") else {
    unreachable!();
};
assert_eq!(a, zero);
Source§

fn is_zero(&self) -> bool

Validate whether an integer is zero.

§Examples
use rmatrix_ks::number::{instances::integer::Integer, traits::zero::Zero};

let a = Integer::zero();
assert!(a.is_zero());
let Some(b) = Integer::of(true, &[1, 6]) else {
    unreachable!();
};
assert!(!b.is_zero());
Source§

impl Eq for Integer

Source§

impl StructuralPartialEq for Integer

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V