#![doc = include_str!("../README.md")]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![forbid(unsafe_code)]
#![warn(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "nightly", feature(test))]
extern crate alloc;
#[cfg(all(feature = "nightly", test))]
extern crate test;
use alloc::vec::Vec;
mod add;
mod assign;
mod assign_double;
mod assign_integral;
mod assign_string;
pub mod base;
mod bits;
mod builtin_int_methods;
mod capacity;
mod comparisons;
mod comparisons_double;
mod comparisons_integral;
mod division;
#[allow(unknown_lints)]
#[allow(clippy::doc_lazy_continuation)]
#[allow(clippy::doc_overindented_list_items)]
pub mod docs;
mod exponentiation;
mod fits;
mod fmt;
mod from_double;
mod from_integral;
mod from_string;
mod gcd;
mod invert;
mod is_odd_is_even;
mod is_signed;
mod is_zero;
mod left_shift;
mod macros;
mod multiplication;
mod negate;
mod new;
mod ops;
mod print_internal;
mod random;
mod right_shift;
mod sign;
mod size;
mod to_double;
mod to_integral;
mod to_string;
mod to_twos_complement;
mod uints;
mod unary_ops;
mod util;
mod zero_and_one;
pub use assign::Assign;
pub use base::{Base, BaseError};
pub use exponentiation::Pow; pub use fits::Fits;
pub use from_string::ParseError;
#[cfg(feature = "rand")]
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
pub use random::RandomArbi;
pub type Digit = u32;
pub type BitCount = u128;
#[allow(dead_code)]
type SDigit = i32;
type DDigit = u64;
type SDDigit = i64;
#[allow(dead_code)]
type QDigit = u128;
#[allow(dead_code)]
type SQDigit = i128;
#[derive(Clone, Debug, Default)]
pub struct Arbi {
vec: Vec<Digit>,
neg: bool,
}
impl Arbi {
#[allow(clippy::unnecessary_cast)]
pub const BASE: DDigit = (1 as DDigit) << Digit::BITS;
#[inline(always)]
fn trim(&mut self) {
while !self.vec.is_empty() && self.vec.last() == Some(&0) {
self.vec.pop();
}
if self.vec.is_empty() {
self.neg = false;
}
}
#[inline(always)]
fn make_zero(&mut self) {
self.vec.clear();
self.neg = false;
}
#[inline(always)]
fn make_one(&mut self, neg: bool) {
self.vec.resize(1, 0);
self.vec[0] = 1;
self.neg = neg;
}
pub(crate) fn with_capacity_and_copy(capacity: usize, arbi: &Arbi) -> Self {
let mut new_vec = Vec::with_capacity(capacity);
new_vec.extend_from_slice(&arbi.vec);
Self {
vec: new_vec,
neg: arbi.neg,
}
}
#[allow(dead_code)]
pub(crate) fn from_digits(digits: Vec<Digit>, is_negative: bool) -> Self {
let mut arbi = Arbi {
neg: is_negative,
vec: digits,
};
arbi.trim();
arbi
}
#[allow(dead_code)]
pub(crate) fn from_slice(digits: &[Digit], is_negative: bool) -> Self {
let mut arbi = Arbi {
neg: is_negative,
vec: digits.to_vec(),
};
arbi.trim();
arbi
}
#[allow(dead_code)]
pub(crate) fn assign_slice(&mut self, digits: &[Digit], is_negative: bool) {
self.vec.clear();
self.vec.extend_from_slice(digits);
self.neg = is_negative;
self.trim();
}
pub(crate) fn swap_if_smaller_capacity(&mut self, other: &mut Self) {
if other.vec.capacity() > self.vec.capacity() {
core::mem::swap(self, other);
}
}
}