pub struct Arbi { /* private fields */ }Expand description
Arbitrary Precision Integer type.
§Internal Representation
The internal representation of an Arbi integer consists of a boolean field
encoding whether or not the integer is negative, as well as a Vec of
Digits (an unsigned integer type) encoding the absolute value of the
integer with least significant digits first. A “digit” is a
base-Arbi::BASE digit (i.e. an integer in
\( [0, \text{Arbi::BASE} - 1] = [0, \text{Digit::MAX}] \)).
§Limits
Arbi::MAX_CAPACITY:Vecis limited toisize::MAXbytes in capacity. A digit has size in bytescore::mem::size_of::<Digit>(). The maximum capacity is thereforeisize::MAX / core::mem::size_of::<Digit>().Arbi::MAX_BITS: At maximum capacity,Arbi::MAX_BITSbits are available to represent the absolute value of theArbiinteger.
When resizing/reserving more space, if the needed space exceeds isize::MAX
in bytes, the Vec allocation methods currently used will panic to signal
capacity overflow. The Vec allocation methods also panic if the
allocator reports allocation failure. In practice, memory allocation
typically fails for less than isize::MAX in bytes.
In the future, we may choose to explicitly handle such errors to avoid a panic, where it makes sense.
§Panic
In general:
-
This crate prefers not to panic, unless for good reason.
-
If an operation can panic, it will be clearly documented.
-
Operations typically only panic because they are enforcing consistency with the behavior of primitive integer types. For example, a division by zero panics. Similarly,
Arbi::from_str_radix()andArbi::to_string_radix()panic if theradixargument value is invalid, consistent with the built-in analogues.Arbi::from_str_base()andArbi::to_string_base()are equivalent, except that they do not panic on invalid bases. -
Because
Vecis limited toisize::MAXbytes in capacity, if an operation would lead to anArbirequiring more thanisize::MAXbytes in capacity, then the currentVecallocation methods used will panic. TheVecallocation methods also panic if the allocator reports allocation failure. In practice, memory allocation typically fails for less thanisize::MAXin bytes. -
Some operations, such as exponentiation, might know in advance that the result will need a capacity that will exceed
Vec’s limits. In such cases, the program will panic immediately, rather than allow it to run a long computation that is guaranteed to exhaust memory.
Implementations§
Source§impl Arbi
impl Arbi
Sourcepub fn assign_str_radix(
&mut self,
s: &str,
radix: u32,
) -> Result<(), ParseError>
pub fn assign_str_radix( &mut self, s: &str, radix: u32, ) -> Result<(), ParseError>
Assign the integer value the provided string represents to this Arbi
integer.
§Panic
Panics if radix is not in \( [2, 36] \). Use
Arbi::assign_str_base for a panic-free version.
§Examples
use arbi::{Arbi, ParseError};
let mut x = Arbi::with_capacity(10);
assert_eq!(x, 0);
match x.assign_str_radix("123456789", 10) {
Ok(_) => assert_eq!(x, 123456789),
Err(e) => match e {
ParseError::InvalidDigit => panic!("Found an invalid digit"),
ParseError::Empty => panic!("Found an empty string"),
},
}
if let Err(e) = x.assign_str_radix("7c2ecdfacad74e0f0101b", 16) {
panic!("Parsing error: {}", e);
}
assert_eq!(x, 0x7c2ecdfacad74e0f0101b_u128);The Arbi integer will remain in its original state if a parsing error
occurs:
use arbi::{Arbi, Assign, ParseError};
let mut x = Arbi::from(u128::MAX);
assert_eq!(x, u128::MAX);
match x.assign_str_radix("7c2ecdfacad74e0f0101b", 15) {
Ok(_) => panic!(),
Err(e) => {
assert!(matches!(e, ParseError::InvalidDigit));
assert_eq!(x, u128::MAX);
}
}Panics on invalid radix values
use arbi::Arbi;
let mut x = Arbi::with_capacity(5);
x.assign_str_radix("7c2ecdfacad74e0f0101b", 37);Example invalid strings
use arbi::{Arbi, ParseError};
let mut a = Arbi::zero();
assert!(matches!(
a.assign_str_radix(" - ", 10),
Err(ParseError::Empty)
));
assert!(matches!(
a.assign_str_radix("ffff", 10),
Err(ParseError::InvalidDigit)
));Sourcepub fn assign_str_base(&mut self, s: &str, base: Base) -> Result<(), ParseError>
pub fn assign_str_base(&mut self, s: &str, base: Base) -> Result<(), ParseError>
Assign the integer value the provided string represents to this Arbi
integer.
§Examples
use arbi::{
base::{DEC, HEX},
Arbi, ParseError,
};
let mut x = Arbi::with_capacity(10);
assert_eq!(x, 0);
match x.assign_str_base("123456789", DEC) {
Ok(_) => assert_eq!(x, 123456789),
Err(e) => match e {
ParseError::InvalidDigit => panic!("Found an invalid digit"),
ParseError::Empty => panic!("Found an empty string"),
},
}
if let Err(e) = x.assign_str_base("7c2ecdfacad74e0f0101b", HEX) {
panic!("Parsing error: {}", e);
}
assert_eq!(x, 0x7c2ecdfacad74e0f0101b_u128);The Arbi integer will remain in its original state if a parsing error
occurs:
use arbi::{Arbi, Base, ParseError};
let mut x = Arbi::from(u128::MAX);
assert_eq!(x, u128::MAX);
match x
.assign_str_base("7c2ecdfacad74e0f0101b", Base::try_from(15).unwrap())
{
Ok(_) => panic!(),
Err(e) => {
assert!(matches!(e, ParseError::InvalidDigit));
assert_eq!(x, u128::MAX);
}
}Example invalid strings:
use arbi::{base::DEC, Arbi, ParseError};
let mut a = Arbi::zero();
assert!(matches!(
a.assign_str_base(" - ", DEC),
Err(ParseError::Empty)
));
assert!(matches!(
a.assign_str_base("ffff", DEC),
Err(ParseError::InvalidDigit)
));Source§impl Arbi
impl Arbi
Sourcepub fn set_bit(&mut self, i: usize) -> &mut Self
pub fn set_bit(&mut self, i: usize) -> &mut Self
Set bit i (zero-based indexing), acting as if the integer is
nonnegative, but preserving its original sign in the result.
§Examples
use arbi::Arbi;
// 11000000111001
let mut a = Arbi::from(12345);
a.set_bit(1);
// 11000000111011
assert_eq!(a, 12347);
a.set_bit(14);
// 111000000111011
assert_eq!(a, 28731);§Complexity
- \( O(1) \) when setting an existing bit.
- \( O(n) \) when setting a bit outside the current bit width, as this requires resizing.
Source§impl Arbi
impl Arbi
Sourcepub fn div(&self, other: &Arbi) -> (Arbi, Arbi)
pub fn div(&self, other: &Arbi) -> (Arbi, Arbi)
Computes both the quotient and remainder of division of this Arbi
object by another Arbi object and returns both the quotient and the
remainder as a pair.
In Rust, integer division rounds towards zero
and given remainder = dividend % divisor, remainder will have the
same sign as the dividend. The behavior of division in this crate is
consistent with that of division of integer primitive types.
Generally speaking, division algorithms calculate both the quotient and remainder simultaneously. If you need both, it is best to ask for both in one step rather than use the / and % operators in turn.
§Parameters
other: The divisor.
§Panic
§Return
A pair of Arbi integers where the first element is the quotient and
the second element is the remainder.
§Examples
use arbi::{Arbi, Assign};
let num = Arbi::from_str_radix(
"100000000000000000000000000000000000000000000000000",
16,
)
.unwrap();
let mut den =
Arbi::from_str_radix("40000000000000000000000000000000000000", 16)
.unwrap();
let (quo, rem) = num.div(&den);
assert_eq!(quo, 1125899906842624_u64);
assert_eq!(rem, 0);
if let Err(e) = den.assign_str_radix(
"-10b67ec03f7d363506c60c8c877b6f92be8f41518c16aa3187",
16,
) {
panic!("Parse error: {}", e);
}
let (quo, rem) = num.div(&den);
let expected_rem = Arbi::from_str_radix(
"54e92bc47a9d2e49a6543c40fc47666d59b2c38caac071917",
16,
)
.unwrap();
assert_eq!(quo, -15);
assert_eq!(rem, expected_rem);
// We can also use the / and % operators in turn to get the same result,
// but that would involve two passes through the division algorithm.
assert_eq!(&num / &den, -15);
assert_eq!(&num % &den, expected_rem);Dividing an Arbi integer by zero panics:
use arbi::Arbi;
let x = Arbi::from_str_radix("123456789", 10).unwrap();
let (quo, rem) = x.div(&Arbi::zero());Dividing a primitive integer value by zero panics:
#![allow(unconditional_panic)]
let zero = 0;
let x = -123456789 / zero;§Complexity
\( O(m \cdot n) \)
Source§impl Arbi
impl Arbi
Sourcepub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseError>
pub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseError>
Equivalent to Arbi::from_str_base(), but panics if the base is
invalid (i.e. not in \( [2, 36] \)).
§Examples
use arbi::{Arbi, Base};
let x = Arbi::from_str_radix("987654321", 10).unwrap();
assert_eq!(x, 987654321);Sourcepub fn from_str_base(s: &str, base: Base) -> Result<Self, ParseError>
pub fn from_str_base(s: &str, base: Base) -> Result<Self, ParseError>
Construct an integer from a string representing a base-base integer.
Allows leading whitespace and/or a plus/minus sign before the first
base-base digit. base must be an integer in \( [2, 36] \).
Trailing whitespace is ignored.
§Examples
use arbi::{base::DEC, Arbi};
let x = Arbi::from_str_base("987654321", DEC).unwrap();
assert_eq!(x, 987654321);Source§impl Arbi
impl Arbi
Source§impl Arbi
impl Arbi
Sourcepub fn to_f64(&self) -> f64
pub fn to_f64(&self) -> f64
Convert this integer to a floating-point value.
The semantics of this function are consistent with Rust’s built-in behavior for casting from an integer to a float.
§Examples
use arbi::{Arbi, Pow};
let a = Arbi::from(-987654321);
assert_eq!(a.to_f64(), -987654321.0);
let b = Arbi::from(1_u64 << 32);
assert_ne!((&b).pow(31_usize).to_f64(), f64::INFINITY);
assert_eq!((&b).pow(32_usize).to_f64(), f64::INFINITY);§Complexity
\( O(1) \)
Source§impl Arbi
impl Arbi
Sourcepub fn to_i8(&self) -> i8
pub fn to_i8(&self) -> i8
Convert this Arbi integer to a primitive integer type value.
This is “wrapping”.
§Note
From<Arbi>andFrom<&Arbi>are implemented for each primitive integral type and has the same semantics.- In Rust, casting from a larger primitive integer type to a smaller integer type truncates. This function has the same semantics.
§Return
Return the unique value of this target primitive integer type that is
congruent to the Arbi integer, modulo \( 2^{N} \), where \( N \)
is the width of the target type.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y: i32 = x.to_i32();
let z: i16 = x.to_i16();
assert_eq!(y, i32::MIN);
assert_eq!(z, i32::MIN as i16);
assert_eq!(i16::from(&x), i32::MIN as i16);Sourcepub fn to_i8_checked(&self) -> Option<i8>
pub fn to_i8_checked(&self) -> Option<i8>
Convert this Arbi integer to a primitive integer type value.
§Return
Some(value) if the Arbi value fits within the target type’s range,
None otherwise.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y = x.to_i32_checked();
assert_eq!(y, Some(i32::MIN));
let z = x.to_i16_checked();
assert!(z.is_none());Source§impl Arbi
impl Arbi
Sourcepub fn to_i16(&self) -> i16
pub fn to_i16(&self) -> i16
Convert this Arbi integer to a primitive integer type value.
This is “wrapping”.
§Note
From<Arbi>andFrom<&Arbi>are implemented for each primitive integral type and has the same semantics.- In Rust, casting from a larger primitive integer type to a smaller integer type truncates. This function has the same semantics.
§Return
Return the unique value of this target primitive integer type that is
congruent to the Arbi integer, modulo \( 2^{N} \), where \( N \)
is the width of the target type.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y: i32 = x.to_i32();
let z: i16 = x.to_i16();
assert_eq!(y, i32::MIN);
assert_eq!(z, i32::MIN as i16);
assert_eq!(i16::from(&x), i32::MIN as i16);Sourcepub fn to_i16_checked(&self) -> Option<i16>
pub fn to_i16_checked(&self) -> Option<i16>
Convert this Arbi integer to a primitive integer type value.
§Return
Some(value) if the Arbi value fits within the target type’s range,
None otherwise.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y = x.to_i32_checked();
assert_eq!(y, Some(i32::MIN));
let z = x.to_i16_checked();
assert!(z.is_none());Source§impl Arbi
impl Arbi
Sourcepub fn to_i32(&self) -> i32
pub fn to_i32(&self) -> i32
Convert this Arbi integer to a primitive integer type value.
This is “wrapping”.
§Note
From<Arbi>andFrom<&Arbi>are implemented for each primitive integral type and has the same semantics.- In Rust, casting from a larger primitive integer type to a smaller integer type truncates. This function has the same semantics.
§Return
Return the unique value of this target primitive integer type that is
congruent to the Arbi integer, modulo \( 2^{N} \), where \( N \)
is the width of the target type.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y: i32 = x.to_i32();
let z: i16 = x.to_i16();
assert_eq!(y, i32::MIN);
assert_eq!(z, i32::MIN as i16);
assert_eq!(i16::from(&x), i32::MIN as i16);Sourcepub fn to_i32_checked(&self) -> Option<i32>
pub fn to_i32_checked(&self) -> Option<i32>
Convert this Arbi integer to a primitive integer type value.
§Return
Some(value) if the Arbi value fits within the target type’s range,
None otherwise.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y = x.to_i32_checked();
assert_eq!(y, Some(i32::MIN));
let z = x.to_i16_checked();
assert!(z.is_none());Source§impl Arbi
impl Arbi
Sourcepub fn to_i64(&self) -> i64
pub fn to_i64(&self) -> i64
Convert this Arbi integer to a primitive integer type value.
This is “wrapping”.
§Note
From<Arbi>andFrom<&Arbi>are implemented for each primitive integral type and has the same semantics.- In Rust, casting from a larger primitive integer type to a smaller integer type truncates. This function has the same semantics.
§Return
Return the unique value of this target primitive integer type that is
congruent to the Arbi integer, modulo \( 2^{N} \), where \( N \)
is the width of the target type.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y: i32 = x.to_i32();
let z: i16 = x.to_i16();
assert_eq!(y, i32::MIN);
assert_eq!(z, i32::MIN as i16);
assert_eq!(i16::from(&x), i32::MIN as i16);Sourcepub fn to_i64_checked(&self) -> Option<i64>
pub fn to_i64_checked(&self) -> Option<i64>
Convert this Arbi integer to a primitive integer type value.
§Return
Some(value) if the Arbi value fits within the target type’s range,
None otherwise.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y = x.to_i32_checked();
assert_eq!(y, Some(i32::MIN));
let z = x.to_i16_checked();
assert!(z.is_none());Source§impl Arbi
impl Arbi
Sourcepub fn to_i128(&self) -> i128
pub fn to_i128(&self) -> i128
Convert this Arbi integer to a primitive integer type value.
This is “wrapping”.
§Note
From<Arbi>andFrom<&Arbi>are implemented for each primitive integral type and has the same semantics.- In Rust, casting from a larger primitive integer type to a smaller integer type truncates. This function has the same semantics.
§Return
Return the unique value of this target primitive integer type that is
congruent to the Arbi integer, modulo \( 2^{N} \), where \( N \)
is the width of the target type.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y: i32 = x.to_i32();
let z: i16 = x.to_i16();
assert_eq!(y, i32::MIN);
assert_eq!(z, i32::MIN as i16);
assert_eq!(i16::from(&x), i32::MIN as i16);Sourcepub fn to_i128_checked(&self) -> Option<i128>
pub fn to_i128_checked(&self) -> Option<i128>
Convert this Arbi integer to a primitive integer type value.
§Return
Some(value) if the Arbi value fits within the target type’s range,
None otherwise.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y = x.to_i32_checked();
assert_eq!(y, Some(i32::MIN));
let z = x.to_i16_checked();
assert!(z.is_none());Source§impl Arbi
impl Arbi
Sourcepub fn to_isize(&self) -> isize
pub fn to_isize(&self) -> isize
Convert this Arbi integer to a primitive integer type value.
This is “wrapping”.
§Note
From<Arbi>andFrom<&Arbi>are implemented for each primitive integral type and has the same semantics.- In Rust, casting from a larger primitive integer type to a smaller integer type truncates. This function has the same semantics.
§Return
Return the unique value of this target primitive integer type that is
congruent to the Arbi integer, modulo \( 2^{N} \), where \( N \)
is the width of the target type.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y: i32 = x.to_i32();
let z: i16 = x.to_i16();
assert_eq!(y, i32::MIN);
assert_eq!(z, i32::MIN as i16);
assert_eq!(i16::from(&x), i32::MIN as i16);Sourcepub fn to_isize_checked(&self) -> Option<isize>
pub fn to_isize_checked(&self) -> Option<isize>
Convert this Arbi integer to a primitive integer type value.
§Return
Some(value) if the Arbi value fits within the target type’s range,
None otherwise.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y = x.to_i32_checked();
assert_eq!(y, Some(i32::MIN));
let z = x.to_i16_checked();
assert!(z.is_none());Sourcepub fn fits_isize(&self) -> bool
pub fn fits_isize(&self) -> bool
Return true if this integer fits in this primitive integer type,
false otherwise.
§Examples
use arbi::Arbi;
let mut x = Arbi::from(u8::MAX);
assert!(x.fits_u8());
x.incr();
assert!(!x.fits_u8());Source§impl Arbi
impl Arbi
Sourcepub fn to_u8(&self) -> u8
pub fn to_u8(&self) -> u8
Convert this Arbi integer to a primitive integer type value.
This is “wrapping”.
§Note
From<Arbi>andFrom<&Arbi>are implemented for each primitive integral type and has the same semantics.- In Rust, casting from a larger primitive integer type to a smaller integer type truncates. This function has the same semantics.
§Return
Return the unique value of this target primitive integer type that is
congruent to the Arbi integer, modulo \( 2^{N} \), where \( N \)
is the width of the target type.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y: i32 = x.to_i32();
let z: i16 = x.to_i16();
assert_eq!(y, i32::MIN);
assert_eq!(z, i32::MIN as i16);
assert_eq!(i16::from(&x), i32::MIN as i16);Sourcepub fn to_u8_checked(&self) -> Option<u8>
pub fn to_u8_checked(&self) -> Option<u8>
Convert this Arbi integer to a primitive integer type value.
§Return
Some(value) if the Arbi value fits within the target type’s range,
None otherwise.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y = x.to_i32_checked();
assert_eq!(y, Some(i32::MIN));
let z = x.to_i16_checked();
assert!(z.is_none());Source§impl Arbi
impl Arbi
Sourcepub fn to_u16(&self) -> u16
pub fn to_u16(&self) -> u16
Convert this Arbi integer to a primitive integer type value.
This is “wrapping”.
§Note
From<Arbi>andFrom<&Arbi>are implemented for each primitive integral type and has the same semantics.- In Rust, casting from a larger primitive integer type to a smaller integer type truncates. This function has the same semantics.
§Return
Return the unique value of this target primitive integer type that is
congruent to the Arbi integer, modulo \( 2^{N} \), where \( N \)
is the width of the target type.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y: i32 = x.to_i32();
let z: i16 = x.to_i16();
assert_eq!(y, i32::MIN);
assert_eq!(z, i32::MIN as i16);
assert_eq!(i16::from(&x), i32::MIN as i16);Sourcepub fn to_u16_checked(&self) -> Option<u16>
pub fn to_u16_checked(&self) -> Option<u16>
Convert this Arbi integer to a primitive integer type value.
§Return
Some(value) if the Arbi value fits within the target type’s range,
None otherwise.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y = x.to_i32_checked();
assert_eq!(y, Some(i32::MIN));
let z = x.to_i16_checked();
assert!(z.is_none());Source§impl Arbi
impl Arbi
Sourcepub fn to_u32(&self) -> u32
pub fn to_u32(&self) -> u32
Convert this Arbi integer to a primitive integer type value.
This is “wrapping”.
§Note
From<Arbi>andFrom<&Arbi>are implemented for each primitive integral type and has the same semantics.- In Rust, casting from a larger primitive integer type to a smaller integer type truncates. This function has the same semantics.
§Return
Return the unique value of this target primitive integer type that is
congruent to the Arbi integer, modulo \( 2^{N} \), where \( N \)
is the width of the target type.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y: i32 = x.to_i32();
let z: i16 = x.to_i16();
assert_eq!(y, i32::MIN);
assert_eq!(z, i32::MIN as i16);
assert_eq!(i16::from(&x), i32::MIN as i16);Sourcepub fn to_u32_checked(&self) -> Option<u32>
pub fn to_u32_checked(&self) -> Option<u32>
Convert this Arbi integer to a primitive integer type value.
§Return
Some(value) if the Arbi value fits within the target type’s range,
None otherwise.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y = x.to_i32_checked();
assert_eq!(y, Some(i32::MIN));
let z = x.to_i16_checked();
assert!(z.is_none());Source§impl Arbi
impl Arbi
Sourcepub fn to_u64(&self) -> u64
pub fn to_u64(&self) -> u64
Convert this Arbi integer to a primitive integer type value.
This is “wrapping”.
§Note
From<Arbi>andFrom<&Arbi>are implemented for each primitive integral type and has the same semantics.- In Rust, casting from a larger primitive integer type to a smaller integer type truncates. This function has the same semantics.
§Return
Return the unique value of this target primitive integer type that is
congruent to the Arbi integer, modulo \( 2^{N} \), where \( N \)
is the width of the target type.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y: i32 = x.to_i32();
let z: i16 = x.to_i16();
assert_eq!(y, i32::MIN);
assert_eq!(z, i32::MIN as i16);
assert_eq!(i16::from(&x), i32::MIN as i16);Sourcepub fn to_u64_checked(&self) -> Option<u64>
pub fn to_u64_checked(&self) -> Option<u64>
Convert this Arbi integer to a primitive integer type value.
§Return
Some(value) if the Arbi value fits within the target type’s range,
None otherwise.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y = x.to_i32_checked();
assert_eq!(y, Some(i32::MIN));
let z = x.to_i16_checked();
assert!(z.is_none());Source§impl Arbi
impl Arbi
Sourcepub fn to_u128(&self) -> u128
pub fn to_u128(&self) -> u128
Convert this Arbi integer to a primitive integer type value.
This is “wrapping”.
§Note
From<Arbi>andFrom<&Arbi>are implemented for each primitive integral type and has the same semantics.- In Rust, casting from a larger primitive integer type to a smaller integer type truncates. This function has the same semantics.
§Return
Return the unique value of this target primitive integer type that is
congruent to the Arbi integer, modulo \( 2^{N} \), where \( N \)
is the width of the target type.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y: i32 = x.to_i32();
let z: i16 = x.to_i16();
assert_eq!(y, i32::MIN);
assert_eq!(z, i32::MIN as i16);
assert_eq!(i16::from(&x), i32::MIN as i16);Sourcepub fn to_u128_checked(&self) -> Option<u128>
pub fn to_u128_checked(&self) -> Option<u128>
Convert this Arbi integer to a primitive integer type value.
§Return
Some(value) if the Arbi value fits within the target type’s range,
None otherwise.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y = x.to_i32_checked();
assert_eq!(y, Some(i32::MIN));
let z = x.to_i16_checked();
assert!(z.is_none());Source§impl Arbi
impl Arbi
Sourcepub fn to_usize(&self) -> usize
pub fn to_usize(&self) -> usize
Convert this Arbi integer to a primitive integer type value.
This is “wrapping”.
§Note
From<Arbi>andFrom<&Arbi>are implemented for each primitive integral type and has the same semantics.- In Rust, casting from a larger primitive integer type to a smaller integer type truncates. This function has the same semantics.
§Return
Return the unique value of this target primitive integer type that is
congruent to the Arbi integer, modulo \( 2^{N} \), where \( N \)
is the width of the target type.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y: i32 = x.to_i32();
let z: i16 = x.to_i16();
assert_eq!(y, i32::MIN);
assert_eq!(z, i32::MIN as i16);
assert_eq!(i16::from(&x), i32::MIN as i16);Sourcepub fn to_usize_checked(&self) -> Option<usize>
pub fn to_usize_checked(&self) -> Option<usize>
Convert this Arbi integer to a primitive integer type value.
§Return
Some(value) if the Arbi value fits within the target type’s range,
None otherwise.
§Examples
use arbi::Arbi;
let x = Arbi::from(i32::MIN);
let y = x.to_i32_checked();
assert_eq!(y, Some(i32::MIN));
let z = x.to_i16_checked();
assert!(z.is_none());Sourcepub fn fits_usize(&self) -> bool
pub fn fits_usize(&self) -> bool
Return true if this integer fits in this primitive integer type,
false otherwise.
§Examples
use arbi::Arbi;
let mut x = Arbi::from(u8::MAX);
assert!(x.fits_u8());
x.incr();
assert!(!x.fits_u8());Source§impl Arbi
impl Arbi
Sourcepub fn to_string_base(&self, base: Base) -> String
pub fn to_string_base(&self, base: Base) -> String
Sourcepub fn to_string_radix(&self, radix: u32) -> String
pub fn to_string_radix(&self, radix: u32) -> String
Equivalent to Arbi::to_string_base(), but panics if the base is
invalid (i.e. not in \( [2, 36] \)).
§Examples
use arbi::{Arbi, Base};
let a = Arbi::from(123456789);
let s = a.to_string_radix(10);
assert_eq!(s, "123456789");Source§impl Arbi
impl Arbi
Sourcepub const BASE: u64 = 4_294_967_296u64
pub const BASE: u64 = 4_294_967_296u64
Base used for the internal representation of the integer.
Sourcepub const MAX_CAPACITY: usize = 536_870_911usize
pub const MAX_CAPACITY: usize = 536_870_911usize
Maximum capacity for the internal vector of digits.
Vec is limited to isize::MAX bytes in capacity. A digit has size
in bytes core::mem::size_of::<Digit>(). The maximum capacity is
therefore isize::MAX / core::mem::size_of::<Digit>().
Sourcepub const MAX_BITS: u128 = 17_179_869_152u128
pub const MAX_BITS: u128 = 17_179_869_152u128
Maximum capacity for the internal vector of digits, in terms of bits.
This represents the number of bits that can be used to represent the absolute value of the integer when the internal digit vector is at maximum capacity.
This is Arbi::MAX_CAPACITY * Digit::BITS.
Sourcepub fn new() -> Self
pub fn new() -> Self
Default constructor. The integer is initialized to zero and no memory allocation occurs.
Note that Arbi::new(), Arbi::zero(), and Arbi::default() are
all equivalent.
§Examples
use arbi::Arbi;
let zero = Arbi::new();
assert_eq!(zero, 0);§Complexity
\( O(1) \)
Sourcepub fn zero() -> Self
pub fn zero() -> Self
Equivalent to Arbi::new().
§Examples
use arbi::Arbi;
let zero = Arbi::zero();
assert_eq!(zero, 0);§Complexity
\( O(1) \)
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Construct a new Arbi integer with at least the specified capacity, in
terms of Digits.
The integer’s value will be 0.
§Examples
use arbi::Arbi;
let a = Arbi::with_capacity(10);
assert_eq!(a.capacity(), 10);
assert_eq!(a, 0);Panics if the new capacity exceeds Arbi::MAX_CAPACITY digits:
use arbi::Arbi;
let a = Arbi::with_capacity(Arbi::MAX_CAPACITY + 1);§Panic
Panics if the new capacity exceeds isize::MAX bytes (or
Arbi::MAX_CAPACITY digits) or if the allocator reports an allocation
failure.
Sourcepub fn with_capacity_bits(capacity: u128) -> Self
pub fn with_capacity_bits(capacity: u128) -> Self
Construct a new Arbi integer with at least the specified capacity, in
terms of bits.
The integer’s value will be 0.
§Examples
use arbi::{Arbi, Digit};
let a = Arbi::with_capacity_bits(Digit::BITS as u128 - 1);
assert_eq!(a.capacity(), 1);
assert_eq!(a, 0);
let a = Arbi::with_capacity_bits(Digit::BITS as u128);
assert_eq!(a.capacity(), 1);
let a = Arbi::with_capacity_bits(Digit::BITS as u128 + 1);
assert_eq!(a.capacity(), 2);Panics if the new capacity in bits exceeds Arbi::MAX_BITS bits:
use arbi::Arbi;
// Panics with message: "New capacity exceeds `isize::MAX` bytes".
let a = Arbi::with_capacity_bits(Arbi::MAX_BITS + 1);Note that, in practice, while the theoretical limit for the capacity
of a Vec in bytes is isize::MAX, memory allocation failures
typically happen for less.
§Panic
Panics if the new capacity exceeds isize::MAX bytes (or
Arbi::MAX_BITS digits) or if the allocator reports an allocation
failure.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the total number of elements the internal digit vector can hold without reallocating.
§Examples
use arbi::{Arbi, Assign};
let zero = Arbi::zero();
assert_eq!(zero.capacity(), 0);
let mut b = Arbi::with_capacity(10);
assert_eq!(b.capacity(), 10);
b.assign(u64::MAX); // no memory allocation needed
assert_eq!(b, u64::MAX);§Complexity
\( O(1) \)
Sourcepub fn capacity_bits(&self) -> u128
pub fn capacity_bits(&self) -> u128
Return the total number of bits the current capacity can hold to represent the absolute value of this integer.
§Examples
use arbi::{Arbi, Digit};
let zero = Arbi::zero();
assert_eq!(zero.capacity_bits(), 0);
let a = Arbi::with_capacity_bits(Digit::BITS as u128);
assert!(a.capacity_bits() >= Digit::BITS as u128);§Complexitys
\( O(1) \)
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Sourcepub fn abs(&self) -> Arbi
pub fn abs(&self) -> Arbi
Return a new integer representing the absolute value of this integer.
For in-place negation (\( O(1) \) operation), see Arbi::negate().
§Examples
use arbi::Arbi;
let neg = Arbi::from(-123456789);
let pos = neg.abs();
assert_eq!(pos, 123456789);§Complexity
\( O(n) \)
Sourcepub fn sign(&self) -> Ordering
pub fn sign(&self) -> Ordering
Return an Ordering indicating the sign of the number: Ordering::Less
for negative, Ordering::Equal for zero, Ordering::Greater for
positive.
§Examples
use arbi::Arbi;
use core::cmp::Ordering;
let neg = Arbi::from(-123456789);
let zer = Arbi::zero();
let pos = Arbi::from(123456789);
assert_eq!(neg.sign(), Ordering::Less);
assert_eq!(zer.sign(), Ordering::Equal);
assert_eq!(pos.sign(), Ordering::Greater);§Complexity
\( O(1) \)
Trait Implementations§
Source§impl<'a> AddAssign<&'a Arbi> for Arbi
impl<'a> AddAssign<&'a Arbi> for Arbi
§Complexity
\( O(n) \)
Source§fn add_assign(&mut self, other: &'a Arbi)
fn add_assign(&mut self, other: &'a Arbi)
+= operation. Read moreSource§impl AddAssign for Arbi
impl AddAssign for Arbi
§Complexity
\( O(n) \)
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+= operation. Read moreSource§impl Assign<&Arbi> for Arbi
impl Assign<&Arbi> for Arbi
Copies the contents of the argument Arbi integer into this Arbi integer.
If this Arbi integer already has enough capacity to represent value,
then no memory allocation occurs.
Source§impl Assign<&f64> for Arbi
impl Assign<&f64> for Arbi
Source§fn assign(&mut self, d: &f64)
fn assign(&mut self, d: &f64)
Assign a floating-point value to an Arbi.
§Panic
Panics when attempting to convert a NaN or infinity.
§Note
In Rust, when casting a primitive float to a primitive integer type,
NaNs are converted to 0 and values with large magnitudes and
infinities are saturated to the maximum and minimum values of the
integer type.
In contrast, this function panics in these scenarios.
Source§impl Assign<f64> for Arbi
impl Assign<f64> for Arbi
Source§fn assign(&mut self, d: f64)
fn assign(&mut self, d: f64)
Assign a floating-point value to an Arbi.
§Panic
Panics when attempting to convert a NaN or infinity.
§Note
In Rust, when casting a primitive float to a primitive integer type,
NaNs are converted to 0 and values with large magnitudes and
infinities are saturated to the maximum and minimum values of the
integer type.
In contrast, this function panics in these scenarios.
Source§impl<'a> BitAnd<&'a Arbi> for &Arbi
impl<'a> BitAnd<&'a Arbi> for &Arbi
Mathematically, given two integers \( x, y \) with coefficients \( x_{i}, y_{i} \) of their binary representation, the result of \( x \; \& \; y \) (bitwise AND) is an integer \( r \) with base-2 coefficients \( r_{i} \) such that \[ r_{i} = 1 \Longleftrightarrow x_{i} = 1 \wedge y_{i} = 1 \]
Source§impl<'a> BitAndAssign<&'a Arbi> for Arbi
impl<'a> BitAndAssign<&'a Arbi> for Arbi
See BitAnd for the mathematical semantics.
Source§fn bitand_assign(&mut self, rhs: &'a Self)
fn bitand_assign(&mut self, rhs: &'a Self)
&= operation. Read moreSource§impl BitAndAssign for Arbi
impl BitAndAssign for Arbi
See BitAnd for the mathematical semantics.
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&= operation. Read moreSource§impl<'a> BitOr<&'a Arbi> for &Arbi
impl<'a> BitOr<&'a Arbi> for &Arbi
Mathematically, given two integers \( x, y \) with coefficients \( x_{i}, y_{i} \) of their binary representation, the result of \( x \; | \; y \) (bitwise inclusive OR) is an integer \( r \) with base-2 coefficients \( r_{i} \) such that \[ r_{i} = 1 \Longleftrightarrow x_{i} = 1 \lor y_{i} = 1 \]
Source§impl<'a> BitOrAssign<&'a Arbi> for Arbi
impl<'a> BitOrAssign<&'a Arbi> for Arbi
See BitOr for the mathematical semantics.
Source§fn bitor_assign(&mut self, rhs: &'a Self)
fn bitor_assign(&mut self, rhs: &'a Self)
|= operation. Read moreSource§impl BitOrAssign for Arbi
impl BitOrAssign for Arbi
See BitOr for the mathematical semantics.
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|= operation. Read moreSource§impl<'a> BitXor<&'a Arbi> for &Arbi
impl<'a> BitXor<&'a Arbi> for &Arbi
Mathematically, given two integers \( x, y \) with coefficients \( x_{i}, y_{i} \) of their binary representation, the result of \( x \; ^\wedge \; y \) (bitwise exclusive OR) is an integer \( r \) with base-2 coefficients \( r_{i} \) such that \[ r_{i} = 1 \Longleftrightarrow (x_{i} = 1 \wedge y_{i} = 0) \lor (x_{i} = 0 \wedge y_{i} = 1) \]
Source§impl<'a> BitXorAssign<&'a Arbi> for Arbi
impl<'a> BitXorAssign<&'a Arbi> for Arbi
See BitXor for the mathematical semantics.
Source§fn bitxor_assign(&mut self, rhs: &'a Self)
fn bitxor_assign(&mut self, rhs: &'a Self)
^= operation. Read moreSource§impl BitXorAssign for Arbi
impl BitXorAssign for Arbi
See BitXor for the mathematical semantics.
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^= operation. Read moreSource§impl Display for Arbi
impl Display for Arbi
Outputs the base-10 (decimal) representation of an Arbi integer.
§Examples
use arbi::Arbi;
let a = Arbi::from(12345);
assert_eq!(format!("{}", a), "12345");Source§impl<'a> DivAssign<&'a Arbi> for Arbi
impl<'a> DivAssign<&'a Arbi> for Arbi
See the div() method.
Source§fn div_assign(&mut self, rhs: &'a Arbi)
fn div_assign(&mut self, rhs: &'a Arbi)
/= operation. Read moreSource§impl DivAssign for Arbi
impl DivAssign for Arbi
See the div() method.
Source§fn div_assign(&mut self, rhs: Arbi)
fn div_assign(&mut self, rhs: Arbi)
/= operation. Read moreSource§impl From<f64> for Arbi
impl From<f64> for Arbi
Construct an Arbi integer from a floating-point value.
§Panic
Panics when attempting to convert a NaN or infinity.
§Note
In Rust, when casting a primitive float to a primitive integer type,
NaNs are converted to 0 and values with large magnitudes and infinities
are saturated to the maximum and minimum values of the integer type.
In contrast, this function panics when NaN or infinity is encountered.
Otherwise, the semantics of this function are consistent with Rust’s built-in behavior for casting floats to integers.
§Examples
use arbi::Arbi;
let a = Arbi::from(12345.6789);
assert_eq!(a, 12345);
assert_eq!(a, 12345.6789 as i32)Attempting to convert infinity panics.
use arbi::Arbi;
let a = Arbi::from(f64::INFINITY);Attempting to convert NaN panics.
use arbi::Arbi;
let b = Arbi::from(f64::NAN);§Complexity
\( O(1) \)
Source§impl From<i128> for Arbi
impl From<i128> for Arbi
Construct an Arbi integer from this primitive integer type value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u128::MAX);
assert_eq!(a, u128::MAX);
let b = Arbi::from(i128::MIN);
assert_eq!(b, i128::MIN);
// Also works with references
let c = Arbi::from(&i128::MIN);
assert_eq!(c, i128::MIN);§Complexity
\( O(1) \)
Source§impl From<i16> for Arbi
impl From<i16> for Arbi
Construct an Arbi integer from this primitive integer type value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u128::MAX);
assert_eq!(a, u128::MAX);
let b = Arbi::from(i128::MIN);
assert_eq!(b, i128::MIN);
// Also works with references
let c = Arbi::from(&i128::MIN);
assert_eq!(c, i128::MIN);§Complexity
\( O(1) \)
Source§impl From<i32> for Arbi
impl From<i32> for Arbi
Construct an Arbi integer from this primitive integer type value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u128::MAX);
assert_eq!(a, u128::MAX);
let b = Arbi::from(i128::MIN);
assert_eq!(b, i128::MIN);
// Also works with references
let c = Arbi::from(&i128::MIN);
assert_eq!(c, i128::MIN);§Complexity
\( O(1) \)
Source§impl From<i64> for Arbi
impl From<i64> for Arbi
Construct an Arbi integer from this primitive integer type value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u128::MAX);
assert_eq!(a, u128::MAX);
let b = Arbi::from(i128::MIN);
assert_eq!(b, i128::MIN);
// Also works with references
let c = Arbi::from(&i128::MIN);
assert_eq!(c, i128::MIN);§Complexity
\( O(1) \)
Source§impl From<i8> for Arbi
impl From<i8> for Arbi
Construct an Arbi integer from this primitive integer type value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u128::MAX);
assert_eq!(a, u128::MAX);
let b = Arbi::from(i128::MIN);
assert_eq!(b, i128::MIN);
// Also works with references
let c = Arbi::from(&i128::MIN);
assert_eq!(c, i128::MIN);§Complexity
\( O(1) \)
Source§impl From<isize> for Arbi
impl From<isize> for Arbi
Construct an Arbi integer from this primitive integer type value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u128::MAX);
assert_eq!(a, u128::MAX);
let b = Arbi::from(i128::MIN);
assert_eq!(b, i128::MIN);
// Also works with references
let c = Arbi::from(&i128::MIN);
assert_eq!(c, i128::MIN);§Complexity
\( O(1) \)
Source§impl From<u128> for Arbi
impl From<u128> for Arbi
Construct an Arbi integer from this primitive integer type value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u128::MAX);
assert_eq!(a, u128::MAX);
let b = Arbi::from(i128::MIN);
assert_eq!(b, i128::MIN);
// Also works with references
let c = Arbi::from(&i128::MIN);
assert_eq!(c, i128::MIN);§Complexity
\( O(1) \)
Source§impl From<u16> for Arbi
impl From<u16> for Arbi
Construct an Arbi integer from this primitive integer type value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u128::MAX);
assert_eq!(a, u128::MAX);
let b = Arbi::from(i128::MIN);
assert_eq!(b, i128::MIN);
// Also works with references
let c = Arbi::from(&i128::MIN);
assert_eq!(c, i128::MIN);§Complexity
\( O(1) \)
Source§impl From<u32> for Arbi
impl From<u32> for Arbi
Construct an Arbi integer from this primitive integer type value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u128::MAX);
assert_eq!(a, u128::MAX);
let b = Arbi::from(i128::MIN);
assert_eq!(b, i128::MIN);
// Also works with references
let c = Arbi::from(&i128::MIN);
assert_eq!(c, i128::MIN);§Complexity
\( O(1) \)
Source§impl From<u64> for Arbi
impl From<u64> for Arbi
Construct an Arbi integer from this primitive integer type value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u128::MAX);
assert_eq!(a, u128::MAX);
let b = Arbi::from(i128::MIN);
assert_eq!(b, i128::MIN);
// Also works with references
let c = Arbi::from(&i128::MIN);
assert_eq!(c, i128::MIN);§Complexity
\( O(1) \)
Source§impl From<u8> for Arbi
impl From<u8> for Arbi
Construct an Arbi integer from this primitive integer type value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u128::MAX);
assert_eq!(a, u128::MAX);
let b = Arbi::from(i128::MIN);
assert_eq!(b, i128::MIN);
// Also works with references
let c = Arbi::from(&i128::MIN);
assert_eq!(c, i128::MIN);§Complexity
\( O(1) \)
Source§impl From<usize> for Arbi
impl From<usize> for Arbi
Construct an Arbi integer from this primitive integer type value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u128::MAX);
assert_eq!(a, u128::MAX);
let b = Arbi::from(i128::MIN);
assert_eq!(b, i128::MIN);
// Also works with references
let c = Arbi::from(&i128::MIN);
assert_eq!(c, i128::MIN);§Complexity
\( O(1) \)
Source§impl FromStr for Arbi
impl FromStr for Arbi
Source§fn from_str(src: &str) -> Result<Self, Self::Err>
fn from_str(src: &str) -> Result<Self, Self::Err>
Uses Arbi::from_str_radix() with base 10.
§Examples
use arbi::Arbi;
use core::str::FromStr;
let a = Arbi::from_str("-987654321").unwrap();
assert_eq!(a, -987654321);
let b = "123456789".parse::<Arbi>().unwrap();
assert_eq!(b, 123456789);Source§type Err = ParseError
type Err = ParseError
Source§impl<'b> Mul<&'b Arbi> for &Arbi
impl<'b> Mul<&'b Arbi> for &Arbi
Multiply an Arbi integer by another Arbi integer.
§Examples
use arbi::Arbi;
let mut a = Arbi::from(i16::MIN);
let mut b = a.clone();
a = &a * &b;
assert_eq!(a, (i16::MIN as i128).pow(2));
a = a * &b;
assert_eq!(a, (i16::MIN as i128).pow(3));
a *= &b;
assert_eq!(a, (i16::MIN as i128).pow(4));
a *= b;
assert_eq!(a, (i16::MIN as i128).pow(5));
a = &a * &a;
assert_eq!(
a,
Arbi::from_str_radix("40000000000000000000000000000000000000", 16)
.unwrap()
);§Complexity
\( O(n^{\log_{2}(3)}) \approx O(n^{1.58}) \)
Source§impl MulAssign<&Arbi> for Arbi
impl MulAssign<&Arbi> for Arbi
Source§fn mul_assign(&mut self, rhs: &Arbi)
fn mul_assign(&mut self, rhs: &Arbi)
*= operation. Read moreSource§impl MulAssign for Arbi
impl MulAssign for Arbi
Source§fn mul_assign(&mut self, rhs: Arbi)
fn mul_assign(&mut self, rhs: Arbi)
*= operation. Read moreSource§impl Not for &Arbi
impl Not for &Arbi
Unary complement operator. Return a new integer representing the ones’ complement of this integer.
Currently, this involves cloning the referenced Arbi integer.
§Example
use arbi::{Arbi, Assign};
let mut a = Arbi::zero();
a = !&a;
assert_eq!(a, -1);
assert_eq!(a, !0);
a.assign(u16::MAX);
a = !&a;
assert_eq!(a, -65536);
assert_eq!(a, !(u16::MAX as i32));§Complexity
\( O(n) \)
Source§impl Not for Arbi
impl Not for Arbi
Unary complement operator. Return the ones’ complement of this integer.
This is done in-place, using the moved-in value.
§Example
use arbi::{Arbi, Assign};
let mut a = Arbi::zero();
a = !a; // in-place
assert_eq!(a, -1);
assert_eq!(a, !0);
a.assign(u16::MAX);
a = !a; // in-place
assert_eq!(a, -65536);
assert_eq!(a, !(u16::MAX as i32));§Complexity
\( O(n) \)
Source§impl Ord for Arbi
impl Ord for Arbi
Source§impl PartialEq<Arbi> for i128
impl PartialEq<Arbi> for i128
Source§impl PartialEq<Arbi> for i16
impl PartialEq<Arbi> for i16
Source§impl PartialEq<Arbi> for i32
impl PartialEq<Arbi> for i32
Source§impl PartialEq<Arbi> for i64
impl PartialEq<Arbi> for i64
Source§impl PartialEq<Arbi> for i8
impl PartialEq<Arbi> for i8
Source§impl PartialEq<Arbi> for isize
impl PartialEq<Arbi> for isize
Source§impl PartialEq<Arbi> for u128
impl PartialEq<Arbi> for u128
Source§impl PartialEq<Arbi> for u16
impl PartialEq<Arbi> for u16
Source§impl PartialEq<Arbi> for u32
impl PartialEq<Arbi> for u32
Source§impl PartialEq<Arbi> for u64
impl PartialEq<Arbi> for u64
Source§impl PartialEq<Arbi> for u8
impl PartialEq<Arbi> for u8
Source§impl PartialEq<Arbi> for usize
impl PartialEq<Arbi> for usize
Source§impl PartialEq<f64> for Arbi
impl PartialEq<f64> for Arbi
Test if this Arbi integer is equal to a floating-point value.
See also PartialOrd<f64> for Arbi for
a description of the semantics of comparing an Arbi to a floating-point
value.
§Examples
use arbi::Arbi;
let a = Arbi::from(f64::MAX);
assert_eq!(a, f64::MAX);
assert_ne!(a, f64::MIN);
// Reverse also implemented
assert_eq!(f64::MAX, a);
assert_ne!(f64::MIN, a);§Complexity
\( O(1) \)
Source§impl PartialEq<i128> for Arbi
impl PartialEq<i128> for Arbi
Source§impl PartialEq<i16> for Arbi
impl PartialEq<i16> for Arbi
Source§impl PartialEq<i32> for Arbi
impl PartialEq<i32> for Arbi
Source§impl PartialEq<i64> for Arbi
impl PartialEq<i64> for Arbi
Source§impl PartialEq<i8> for Arbi
impl PartialEq<i8> for Arbi
Source§impl PartialEq<isize> for Arbi
impl PartialEq<isize> for Arbi
Source§impl PartialEq<u128> for Arbi
impl PartialEq<u128> for Arbi
Source§impl PartialEq<u16> for Arbi
impl PartialEq<u16> for Arbi
Source§impl PartialEq<u32> for Arbi
impl PartialEq<u32> for Arbi
Source§impl PartialEq<u64> for Arbi
impl PartialEq<u64> for Arbi
Source§impl PartialEq<u8> for Arbi
impl PartialEq<u8> for Arbi
Source§impl PartialEq<usize> for Arbi
impl PartialEq<usize> for Arbi
Source§impl PartialOrd<Arbi> for f64
impl PartialOrd<Arbi> for f64
Source§impl PartialOrd<Arbi> for i128
impl PartialOrd<Arbi> for i128
Compare the value of this primitive integer value to an Arbi integer.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(0 < a);
assert!(u128::MAX > a);
assert!(0 <= a);
assert!(u128::MAX >= a);§Complexity
\( O(1) \)
Source§impl PartialOrd<Arbi> for i16
impl PartialOrd<Arbi> for i16
Compare the value of this primitive integer value to an Arbi integer.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(0 < a);
assert!(u128::MAX > a);
assert!(0 <= a);
assert!(u128::MAX >= a);§Complexity
\( O(1) \)
Source§impl PartialOrd<Arbi> for i32
impl PartialOrd<Arbi> for i32
Compare the value of this primitive integer value to an Arbi integer.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(0 < a);
assert!(u128::MAX > a);
assert!(0 <= a);
assert!(u128::MAX >= a);§Complexity
\( O(1) \)
Source§impl PartialOrd<Arbi> for i64
impl PartialOrd<Arbi> for i64
Compare the value of this primitive integer value to an Arbi integer.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(0 < a);
assert!(u128::MAX > a);
assert!(0 <= a);
assert!(u128::MAX >= a);§Complexity
\( O(1) \)
Source§impl PartialOrd<Arbi> for i8
impl PartialOrd<Arbi> for i8
Compare the value of this primitive integer value to an Arbi integer.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(0 < a);
assert!(u128::MAX > a);
assert!(0 <= a);
assert!(u128::MAX >= a);§Complexity
\( O(1) \)
Source§impl PartialOrd<Arbi> for isize
impl PartialOrd<Arbi> for isize
Compare the value of this primitive integer value to an Arbi integer.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(0 < a);
assert!(u128::MAX > a);
assert!(0 <= a);
assert!(u128::MAX >= a);§Complexity
\( O(1) \)
Source§impl PartialOrd<Arbi> for u128
impl PartialOrd<Arbi> for u128
Compare the value of this primitive integer value to an Arbi integer.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(0 < a);
assert!(u128::MAX > a);
assert!(0 <= a);
assert!(u128::MAX >= a);§Complexity
\( O(1) \)
Source§impl PartialOrd<Arbi> for u16
impl PartialOrd<Arbi> for u16
Compare the value of this primitive integer value to an Arbi integer.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(0 < a);
assert!(u128::MAX > a);
assert!(0 <= a);
assert!(u128::MAX >= a);§Complexity
\( O(1) \)
Source§impl PartialOrd<Arbi> for u32
impl PartialOrd<Arbi> for u32
Compare the value of this primitive integer value to an Arbi integer.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(0 < a);
assert!(u128::MAX > a);
assert!(0 <= a);
assert!(u128::MAX >= a);§Complexity
\( O(1) \)
Source§impl PartialOrd<Arbi> for u64
impl PartialOrd<Arbi> for u64
Compare the value of this primitive integer value to an Arbi integer.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(0 < a);
assert!(u128::MAX > a);
assert!(0 <= a);
assert!(u128::MAX >= a);§Complexity
\( O(1) \)
Source§impl PartialOrd<Arbi> for u8
impl PartialOrd<Arbi> for u8
Compare the value of this primitive integer value to an Arbi integer.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(0 < a);
assert!(u128::MAX > a);
assert!(0 <= a);
assert!(u128::MAX >= a);§Complexity
\( O(1) \)
Source§impl PartialOrd<Arbi> for usize
impl PartialOrd<Arbi> for usize
Compare the value of this primitive integer value to an Arbi integer.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(0 < a);
assert!(u128::MAX > a);
assert!(0 <= a);
assert!(u128::MAX >= a);§Complexity
\( O(1) \)
Source§impl PartialOrd<f64> for &Arbi
impl PartialOrd<f64> for &Arbi
Source§impl PartialOrd<f64> for Arbi
impl PartialOrd<f64> for Arbi
Compare this Arbi integer to a floating-point value.
These comparisons are designed to be consistent with IEEE 754, handling special cases like NaNs and infinities.
NaN:
- Operators
==,<,<=,>, and>=returnfalsewhen comparing with NaN. - Operator
!=returnstruewhen comparing with NaN.
Infinities:
- Positive infinity is treated as greater than any
Arbinumber. - Negative infinity is treated as less than any
Arbinumber.
§Examples
use arbi::Arbi;
let a = Arbi::from(987654321.5);
assert_eq!(a, 987654321.0);
assert!(a >= 987654321.0);
assert!(a <= 987654321.0);
assert!(a > 0.0);
assert!(a < u64::MAX);
// Reverse also implemented
assert!(987654321.0 <= a);
assert!(987654321.0 >= a);
assert!(0.0 < a);
assert!(u64::MAX > a);§Complexity
\( O(1) \)
Source§impl PartialOrd<i128> for &Arbi
impl PartialOrd<i128> for &Arbi
Source§impl PartialOrd<i128> for &mut Arbi
impl PartialOrd<i128> for &mut Arbi
Source§impl PartialOrd<i128> for Arbi
impl PartialOrd<i128> for Arbi
Compare the value of this Arbi integer to a primitive integer value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(a > 0);
assert!(a < u128::MAX);
assert!(a >= 0);
assert!(a <= u128::MAX);§Complexity
\( O(1) \)
Source§impl PartialOrd<i16> for &Arbi
impl PartialOrd<i16> for &Arbi
Source§impl PartialOrd<i16> for &mut Arbi
impl PartialOrd<i16> for &mut Arbi
Source§impl PartialOrd<i16> for Arbi
impl PartialOrd<i16> for Arbi
Compare the value of this Arbi integer to a primitive integer value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(a > 0);
assert!(a < u128::MAX);
assert!(a >= 0);
assert!(a <= u128::MAX);§Complexity
\( O(1) \)
Source§impl PartialOrd<i32> for &Arbi
impl PartialOrd<i32> for &Arbi
Source§impl PartialOrd<i32> for &mut Arbi
impl PartialOrd<i32> for &mut Arbi
Source§impl PartialOrd<i32> for Arbi
impl PartialOrd<i32> for Arbi
Compare the value of this Arbi integer to a primitive integer value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(a > 0);
assert!(a < u128::MAX);
assert!(a >= 0);
assert!(a <= u128::MAX);§Complexity
\( O(1) \)
Source§impl PartialOrd<i64> for &Arbi
impl PartialOrd<i64> for &Arbi
Source§impl PartialOrd<i64> for &mut Arbi
impl PartialOrd<i64> for &mut Arbi
Source§impl PartialOrd<i64> for Arbi
impl PartialOrd<i64> for Arbi
Compare the value of this Arbi integer to a primitive integer value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(a > 0);
assert!(a < u128::MAX);
assert!(a >= 0);
assert!(a <= u128::MAX);§Complexity
\( O(1) \)
Source§impl PartialOrd<i8> for &Arbi
impl PartialOrd<i8> for &Arbi
Source§impl PartialOrd<i8> for &mut Arbi
impl PartialOrd<i8> for &mut Arbi
Source§impl PartialOrd<i8> for Arbi
impl PartialOrd<i8> for Arbi
Compare the value of this Arbi integer to a primitive integer value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(a > 0);
assert!(a < u128::MAX);
assert!(a >= 0);
assert!(a <= u128::MAX);§Complexity
\( O(1) \)
Source§impl PartialOrd<isize> for &Arbi
impl PartialOrd<isize> for &Arbi
Source§impl PartialOrd<isize> for &mut Arbi
impl PartialOrd<isize> for &mut Arbi
Source§impl PartialOrd<isize> for Arbi
impl PartialOrd<isize> for Arbi
Compare the value of this Arbi integer to a primitive integer value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(a > 0);
assert!(a < u128::MAX);
assert!(a >= 0);
assert!(a <= u128::MAX);§Complexity
\( O(1) \)
Source§impl PartialOrd<u128> for &Arbi
impl PartialOrd<u128> for &Arbi
Source§impl PartialOrd<u128> for &mut Arbi
impl PartialOrd<u128> for &mut Arbi
Source§impl PartialOrd<u128> for Arbi
impl PartialOrd<u128> for Arbi
Compare the value of this Arbi integer to a primitive integer value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(a > 0);
assert!(a < u128::MAX);
assert!(a >= 0);
assert!(a <= u128::MAX);§Complexity
\( O(1) \)
Source§impl PartialOrd<u16> for &Arbi
impl PartialOrd<u16> for &Arbi
Source§impl PartialOrd<u16> for &mut Arbi
impl PartialOrd<u16> for &mut Arbi
Source§impl PartialOrd<u16> for Arbi
impl PartialOrd<u16> for Arbi
Compare the value of this Arbi integer to a primitive integer value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(a > 0);
assert!(a < u128::MAX);
assert!(a >= 0);
assert!(a <= u128::MAX);§Complexity
\( O(1) \)
Source§impl PartialOrd<u32> for &Arbi
impl PartialOrd<u32> for &Arbi
Source§impl PartialOrd<u32> for &mut Arbi
impl PartialOrd<u32> for &mut Arbi
Source§impl PartialOrd<u32> for Arbi
impl PartialOrd<u32> for Arbi
Compare the value of this Arbi integer to a primitive integer value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(a > 0);
assert!(a < u128::MAX);
assert!(a >= 0);
assert!(a <= u128::MAX);§Complexity
\( O(1) \)
Source§impl PartialOrd<u64> for &Arbi
impl PartialOrd<u64> for &Arbi
Source§impl PartialOrd<u64> for &mut Arbi
impl PartialOrd<u64> for &mut Arbi
Source§impl PartialOrd<u64> for Arbi
impl PartialOrd<u64> for Arbi
Compare the value of this Arbi integer to a primitive integer value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(a > 0);
assert!(a < u128::MAX);
assert!(a >= 0);
assert!(a <= u128::MAX);§Complexity
\( O(1) \)
Source§impl PartialOrd<u8> for &Arbi
impl PartialOrd<u8> for &Arbi
Source§impl PartialOrd<u8> for &mut Arbi
impl PartialOrd<u8> for &mut Arbi
Source§impl PartialOrd<u8> for Arbi
impl PartialOrd<u8> for Arbi
Compare the value of this Arbi integer to a primitive integer value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(a > 0);
assert!(a < u128::MAX);
assert!(a >= 0);
assert!(a <= u128::MAX);§Complexity
\( O(1) \)
Source§impl PartialOrd<usize> for &Arbi
impl PartialOrd<usize> for &Arbi
Source§impl PartialOrd<usize> for &mut Arbi
impl PartialOrd<usize> for &mut Arbi
Source§impl PartialOrd<usize> for Arbi
impl PartialOrd<usize> for Arbi
Compare the value of this Arbi integer to a primitive integer value.
This is implemented for all primitive integer types.
§Examples
use arbi::Arbi;
let a = Arbi::from(u64::MAX);
assert!(a > 0);
assert!(a < u128::MAX);
assert!(a >= 0);
assert!(a <= u128::MAX);§Complexity
\( O(1) \)
Source§impl PartialOrd for Arbi
impl PartialOrd for Arbi
Source§impl<'a> RemAssign<&'a Arbi> for Arbi
impl<'a> RemAssign<&'a Arbi> for Arbi
See the div() method.
Source§fn rem_assign(&mut self, rhs: &'a Arbi)
fn rem_assign(&mut self, rhs: &'a Arbi)
%= operation. Read moreSource§impl RemAssign for Arbi
impl RemAssign for Arbi
See the div() method.
Source§fn rem_assign(&mut self, rhs: Arbi)
fn rem_assign(&mut self, rhs: Arbi)
%= operation. Read moreSource§impl Shl<u32> for &Arbi
impl Shl<u32> for &Arbi
Return an Arbi integer representing this integer left-shifted shift bit
positions with vacated bits zero-filled.
Mathematically, the value of the resulting integer is \[ x \times 2^{\text{shift}} \] where \( x \) is the big integer.
This is consistent with Rust’s built-in behavior for left-shifting integers by an unsigned integer value.
§Examples
use arbi::Arbi;
assert_eq!(Arbi::zero() << 1_usize, 0);
assert_eq!(0 << 1, 0);
let mut a = Arbi::from(-1);
a <<= 0_usize;
assert_eq!(a, -1);
assert_eq!(a, -1 << 0);
a <<= 1_usize; // in-place
assert_eq!(a, -2);
assert_eq!(a, -1 << 1);
a = a << 1_usize; // in-place
assert_eq!(a, -4);
assert_eq!(a, -1 << 2);
a = &a << 1_usize; // clones (currently)
assert_eq!(a, -8);
assert_eq!(a, -1 << 3);§Complexity
\( O(n) \)
Source§impl Shl<usize> for &Arbi
impl Shl<usize> for &Arbi
Return an Arbi integer representing this integer left-shifted shift bit
positions with vacated bits zero-filled.
Mathematically, the value of the resulting integer is \[ x \times 2^{\text{shift}} \] where \( x \) is the big integer.
This is consistent with Rust’s built-in behavior for left-shifting integers by an unsigned integer value.
§Examples
use arbi::Arbi;
assert_eq!(Arbi::zero() << 1_usize, 0);
assert_eq!(0 << 1, 0);
let mut a = Arbi::from(-1);
a <<= 0_usize;
assert_eq!(a, -1);
assert_eq!(a, -1 << 0);
a <<= 1_usize; // in-place
assert_eq!(a, -2);
assert_eq!(a, -1 << 1);
a = a << 1_usize; // in-place
assert_eq!(a, -4);
assert_eq!(a, -1 << 2);
a = &a << 1_usize; // clones (currently)
assert_eq!(a, -8);
assert_eq!(a, -1 << 3);§Complexity
\( O(n) \)
Source§impl<'a> ShlAssign<&'a u32> for Arbi
impl<'a> ShlAssign<&'a u32> for Arbi
See Shl<usize> for &Arbi.
Source§fn shl_assign(&mut self, rhs: &'a u32)
fn shl_assign(&mut self, rhs: &'a u32)
<<= operation. Read moreSource§impl<'a> ShlAssign<&'a usize> for Arbi
impl<'a> ShlAssign<&'a usize> for Arbi
See Shl<usize> for &Arbi.
Source§fn shl_assign(&mut self, rhs: &'a usize)
fn shl_assign(&mut self, rhs: &'a usize)
<<= operation. Read moreSource§impl ShlAssign<u32> for Arbi
impl ShlAssign<u32> for Arbi
See Shl<usize> for &Arbi.
Source§fn shl_assign(&mut self, rhs: u32)
fn shl_assign(&mut self, rhs: u32)
<<= operation. Read moreSource§impl ShlAssign<usize> for Arbi
impl ShlAssign<usize> for Arbi
See Shl<usize> for &Arbi.
Source§fn shl_assign(&mut self, rhs: usize)
fn shl_assign(&mut self, rhs: usize)
<<= operation. Read moreSource§impl Shr<usize> for &Arbi
impl Shr<usize> for &Arbi
Return a new integer representing this integer right-shifted rhs bit
positions. This is an arithmetic right shift with sign extension.
Mathematically, the value of the resulting integer is \( \frac{x}{2^{\text{shift}}} \), rounded down: \[ \left\lfloor \frac{x}{2^{\text{shift}}} \right\rfloor \] where \( x \) is the big integer.
This is consistent with Rust’s built-in behavior for right shifting primitive integer type values.
§Note
Currently, when right-shifting a reference to an Arbi (&Arbi), the
operation involves cloning the Arbi integer, which incurs memory
allocation. To avoid these allocations, prefer using the in-place
right-shift operator >>= on a mutable reference (&mut Arbi), or the
move-based right-shift operator >> on an Arbi instance.
§Examples
use arbi::Arbi;
let mut a = Arbi::from(-987654321);
// In-place
a >>= 1;
assert_eq!(a, -493827161);
// Also in-place
a = a >> 1;
assert_eq!(a, -246913581);
// Clones the Arbi integer
a = &a >> 1;
assert_eq!(a, -123456791);§Complexity
\( O(n) \)
Source§impl ShrAssign<&usize> for Arbi
impl ShrAssign<&usize> for Arbi
Source§fn shr_assign(&mut self, rhs: &usize)
fn shr_assign(&mut self, rhs: &usize)
>>= operation. Read moreSource§impl ShrAssign<usize> for Arbi
impl ShrAssign<usize> for Arbi
Source§fn shr_assign(&mut self, rhs: usize)
fn shr_assign(&mut self, rhs: usize)
>>= operation. Read moreSource§impl<'a> SubAssign<&'a Arbi> for Arbi
impl<'a> SubAssign<&'a Arbi> for Arbi
§Complexity
\( O(n) \)
Source§fn sub_assign(&mut self, other: &'a Arbi)
fn sub_assign(&mut self, other: &'a Arbi)
-= operation. Read moreSource§impl SubAssign for Arbi
impl SubAssign for Arbi
§Complexity
\( O(n) \)
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
-= operation. Read more