Add conversions for BigInt/BigUint.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user