Add conversions for BigInt/BigUint.

This commit is contained in:
2018-05-05 19:41:30 -07:00
parent b01c59a094
commit c34629aa47
2 changed files with 46 additions and 4 deletions

View File

@@ -1,4 +1,6 @@
use cryptonum::unsigned::{UCN,divmod};
use num::BigInt;
use num::bigint::Sign;
use std::fmt;
use std::cmp::Ordering;
use std::fmt::Write;
@@ -102,6 +104,15 @@ impl Into<UCN> for SCN {
}
}
impl From<SCN> for BigInt {
fn from(x: SCN) -> BigInt {
let sign = if x.is_negative() { Sign::Minus } else { Sign::Plus };
let numbytes = x.value.contents.len() * 8;
let bytes = x.value.to_bytes(numbytes);
BigInt::from_bytes_be(sign, &bytes)
}
}
//------------------------------------------------------------------------------
//
// Comparisons