pub struct Integer {
pub sign: bool,
/* private fields */
}Expand description
Integer type with no size limit.
Fields§
§sign: boolSign of the number.
Implementations§
Source§impl Integer
impl Integer
Sourcepub fn of(sign: bool, digits: &[u8]) -> Option<Self>
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);Trait Implementations§
Source§impl Integral for Integer
Implement the concept of Integral for Integer.
impl Integral for Integer
Implement the concept of Integral for Integer.
Source§fn quot_rem(self, rhs: Self) -> (Self, Self)
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)
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
fn to_integer(self) -> Integer
Convert the integral number to an integer.
Source§fn quotient(self, rhs: Self) -> Self
fn quotient(self, rhs: Self) -> Self
Calculating the quotient of two integers, rounding the result towards zero.
Source§fn remainder(self, rhs: Self) -> Self
fn remainder(self, rhs: Self) -> Self
Calculating the remainder corresponding to the quotient rounded towards zero.
Source§impl Number for Integer
Implement the concept of NUMBER for the integer number.
impl Number for Integer
Implement the concept of NUMBER for the integer number.
Source§fn absolute_value(&self) -> Self
fn absolute_value(&self) -> Self
Calculate the absolute value of a number.
Source§fn sign_number(&self) -> Self
fn sign_number(&self) -> Self
Calculate the sign of a number.
Source§fn from_integer(integer_number: Integer) -> Self
fn from_integer(integer_number: Integer) -> Self
Convert an integer to another numeric type.
Source§impl One for Integer
impl One for Integer
Source§impl Ord for Integer
Implement Ord for the integer number.
impl Ord for Integer
Implement Ord for the integer number.
Source§impl PartialOrd for Integer
Implement PartialOrd for the integer number.
impl PartialOrd for Integer
Implement PartialOrd for the integer number.
Source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
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));Source§impl Real for Integer
Implement the concept of Real for Integer.
impl Real for Integer
Implement the concept of Real for Integer.
Source§fn to_rational(self) -> Rational
fn to_rational(self) -> Rational
Convert a real number to a rational number.
Source§impl Zero for Integer
Implement the concept of ZERO for the integer number.
impl Zero for Integer
Implement the concept of ZERO for the integer number.
impl Eq for Integer
impl StructuralPartialEq for Integer
Auto Trait Implementations§
impl Freeze for Integer
impl RefUnwindSafe for Integer
impl Send for Integer
impl Sync for Integer
impl Unpin for Integer
impl UnwindSafe for Integer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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