2020-02-12 22:29:57 -05:00
|
|
|
//! Arbitrarily large integers
|
2020-02-12 23:10:08 -05:00
|
|
|
//!
|
|
|
|
//! Traits to implement:
|
|
|
|
//! * Add
|
|
|
|
//! * AddAssign
|
|
|
|
//! * Div
|
|
|
|
//! * DivAssign
|
|
|
|
//! * Mul
|
|
|
|
//! * MulAssign
|
|
|
|
//! * Neg
|
|
|
|
//! * Rem
|
|
|
|
//! * RemAssign
|
|
|
|
//! * Sub
|
|
|
|
//! * SubAssign
|
2020-02-14 10:14:22 -05:00
|
|
|
use crate::num::*;
|
2020-02-12 22:29:57 -05:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct BigInt {
|
|
|
|
inner: Vec<usize>,
|
2020-02-12 23:10:08 -05:00
|
|
|
sign: Sign,
|
2020-02-12 22:29:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for BigInt {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
inner: vec![],
|
2020-02-12 23:10:08 -05:00
|
|
|
sign: Sign::Positive,
|
2020-02-12 22:29:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-12 23:10:08 -05:00
|
|
|
impl<T: Unsigned> From<T> for BigInt {
|
2020-02-12 22:29:57 -05:00
|
|
|
fn from(n: T) -> Self {
|
|
|
|
let mut new = Self::default();
|
|
|
|
|
2020-02-12 23:10:08 -05:00
|
|
|
if n > T::max_value() {
|
2020-02-13 17:13:25 -05:00
|
|
|
new.split(n);
|
2020-02-12 22:29:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
new
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-12 23:10:08 -05:00
|
|
|
impl BigInt {
|
2020-02-13 17:13:25 -05:00
|
|
|
pub fn new() -> Self {
|
|
|
|
Self::default()
|
|
|
|
}
|
|
|
|
|
2020-02-12 22:29:57 -05:00
|
|
|
/// Split an unsigned number into BigInt parts
|
2020-02-13 17:13:25 -05:00
|
|
|
fn split<T: Unsigned>(&mut self, num: T) -> Vec<usize> {
|
2020-02-12 22:29:57 -05:00
|
|
|
// Pretty easy if you don't actually need to split the value!
|
2020-02-12 23:10:08 -05:00
|
|
|
if num < T::max_value() {
|
2020-02-13 17:13:25 -05:00
|
|
|
todo!();
|
|
|
|
// return vec![num as usize];
|
2020-02-12 22:29:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
todo!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2020-02-13 17:13:25 -05:00
|
|
|
mod tests {}
|