rusty-numbers/src/bigint.rs

90 lines
1.4 KiB
Rust

//! \[WIP\] Arbitrarily large integers
//!
//! Traits to implement:
//! * Add
//! * AddAssign
//! * Div
//! * DivAssign
//! * Mul
//! * MulAssign
//! * Neg
//! * Rem
//! * RemAssign
//! * Sub
//! * SubAssign
use crate::num::*;
#[derive(Clone, Debug)]
pub struct BigInt {
inner: Vec<usize>,
sign: Sign,
}
impl Default for BigInt {
fn default() -> Self {
Self {
inner: vec![],
sign: Sign::Positive,
}
}
}
impl<T: Unsigned> From<T> for BigInt {
fn from(n: T) -> Self {
let mut new = Self::default();
if n > T::max_value() {
new.split(n);
}
new
}
}
impl From<&str> for BigInt {
fn from(_: &str) -> Self {
unimplemented!()
}
}
impl From<String> for BigInt {
fn from(_: String) -> Self {
unimplemented!()
}
}
impl BigInt {
pub fn new() -> Self {
Self::default()
}
pub fn shrink_to_fit(&mut self) {
todo!();
}
pub fn from_str_radix() {
todo!();
}
/// Split an unsigned number into BigInt parts
fn split<T: Unsigned>(&mut self, num: T) -> Vec<usize> {
// Pretty easy if you don't actually need to split the value!
if num < T::max_value() {
todo!();
// return vec![num as usize];
}
todo!();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn sanity_checks() {
}
}