rusty-numbers/src/bigint.rs

90 lines
1.4 KiB
Rust
Raw Normal View History

//! \[WIP\] 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
use crate::num::*;
2020-02-12 22:29:57 -05:00
#[derive(Clone, Debug)]
2020-02-12 22:29:57 -05:00
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
}
}
impl From<&str> for BigInt {
fn from(_: &str) -> Self {
unimplemented!()
}
}
impl From<String> for BigInt {
fn from(_: String) -> Self {
unimplemented!()
}
}
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-24 16:30:59 -05:00
pub fn shrink_to_fit(&mut self) {
todo!();
}
pub fn from_str_radix() {
todo!();
}
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-24 16:30:59 -05:00
mod tests {
use super::*;
#[test]
fn sanity_checks() {
}
}