58 lines
965 B
Rust
58 lines
965 B
Rust
|
//! Arbitrarily large integers
|
||
|
use crate::Unsigned;
|
||
|
|
||
|
#[derive(Debug)]
|
||
|
enum BigIntSign {
|
||
|
Positive,
|
||
|
Negative
|
||
|
}
|
||
|
|
||
|
#[derive(Debug)]
|
||
|
pub struct BigInt {
|
||
|
inner: Vec<usize>,
|
||
|
sign: BigIntSign,
|
||
|
}
|
||
|
|
||
|
impl Default for BigInt {
|
||
|
fn default() -> Self {
|
||
|
Self {
|
||
|
inner: vec![],
|
||
|
sign: BigIntSign::Positive,
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl From<T: Unsigned> for BigInt {
|
||
|
fn from(n: T) -> Self {
|
||
|
let mut new = Self::default();
|
||
|
|
||
|
if n > usize::max_value() {
|
||
|
new.inner = Self.split(n);
|
||
|
}
|
||
|
|
||
|
new
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl<T: Unsigned> BigInt {
|
||
|
/// Split an unsigned number into BigInt parts
|
||
|
fn split(num: T) -> Vec<usize> {
|
||
|
// Pretty easy if you don't actually need to split the value!
|
||
|
if num < usize::max_value() {
|
||
|
return vec![T::into()];
|
||
|
}
|
||
|
|
||
|
todo!();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl BigInt {
|
||
|
pub fn new() -> Self {
|
||
|
Self::default()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[cfg(test)]
|
||
|
mod tests {
|
||
|
|
||
|
}
|