rusty-numbers/src/bigint.rs
2020-02-14 10:14:22 -05:00

63 lines
1.0 KiB
Rust

//! Arbitrarily large integers
//!
//! Traits to implement:
//! * Add
//! * AddAssign
//! * Div
//! * DivAssign
//! * Mul
//! * MulAssign
//! * Neg
//! * Rem
//! * RemAssign
//! * Sub
//! * SubAssign
use crate::num::*;
#[derive(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 BigInt {
pub fn new() -> Self {
Self::default()
}
/// 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 {}