Skip to content

Commit 29e9745

Browse files
committed
---
yaml --- r: 95201 b: refs/heads/dist-snap c: 01be9e9 h: refs/heads/master i: 95199: 2c42789 v: v3
1 parent 5557c33 commit 29e9745

File tree

2 files changed

+91
-1
lines changed

2 files changed

+91
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 9de7ad2d8c1729b7b11c6d234fc8ef8ce96809bb
9+
refs/heads/dist-snap: 01be9e9904be9c3c492fa0718a9f4677ea02b8f6
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libextra/num/bigint.rs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,52 @@ impl FromPrimitive for BigUint {
547547
}
548548
}
549549

550+
pub trait ToBigUint {
551+
fn to_biguint(&self) -> Option<BigUint>;
552+
}
553+
554+
impl ToBigUint for BigInt {
555+
#[inline]
556+
fn to_biguint(&self) -> Option<BigUint> {
557+
if self.sign == Plus {
558+
Some(self.data.clone())
559+
} else if self.sign == Zero {
560+
Some(Zero::zero())
561+
} else {
562+
None
563+
}
564+
}
565+
}
566+
567+
impl ToBigUint for BigUint {
568+
#[inline]
569+
fn to_biguint(&self) -> Option<BigUint> {
570+
Some(self.clone())
571+
}
572+
}
573+
574+
macro_rules! impl_to_biguint(
575+
($T:ty, $from_ty:path) => {
576+
impl ToBigUint for $T {
577+
#[inline]
578+
fn to_biguint(&self) -> Option<BigUint> {
579+
$from_ty(*self)
580+
}
581+
}
582+
}
583+
)
584+
585+
impl_to_biguint!(int, FromPrimitive::from_int)
586+
impl_to_biguint!(i8, FromPrimitive::from_i8)
587+
impl_to_biguint!(i16, FromPrimitive::from_i16)
588+
impl_to_biguint!(i32, FromPrimitive::from_i32)
589+
impl_to_biguint!(i64, FromPrimitive::from_i64)
590+
impl_to_biguint!(uint, FromPrimitive::from_uint)
591+
impl_to_biguint!(u8, FromPrimitive::from_u8)
592+
impl_to_biguint!(u16, FromPrimitive::from_u16)
593+
impl_to_biguint!(u32, FromPrimitive::from_u32)
594+
impl_to_biguint!(u64, FromPrimitive::from_u64)
595+
550596
impl ToStrRadix for BigUint {
551597
fn to_str_radix(&self, radix: uint) -> ~str {
552598
assert!(1 < radix && radix <= 16);
@@ -1140,6 +1186,50 @@ impl FromPrimitive for BigInt {
11401186
}
11411187
}
11421188

1189+
pub trait ToBigInt {
1190+
fn to_bigint(&self) -> Option<BigInt>;
1191+
}
1192+
1193+
impl ToBigInt for BigInt {
1194+
#[inline]
1195+
fn to_bigint(&self) -> Option<BigInt> {
1196+
Some(self.clone())
1197+
}
1198+
}
1199+
1200+
impl ToBigInt for BigUint {
1201+
#[inline]
1202+
fn to_bigint(&self) -> Option<BigInt> {
1203+
if self.is_zero() {
1204+
Some(Zero::zero())
1205+
} else {
1206+
Some(BigInt { sign: Plus, data: self.clone() })
1207+
}
1208+
}
1209+
}
1210+
1211+
macro_rules! impl_to_bigint(
1212+
($T:ty, $from_ty:path) => {
1213+
impl ToBigInt for $T {
1214+
#[inline]
1215+
fn to_bigint(&self) -> Option<BigInt> {
1216+
$from_ty(*self)
1217+
}
1218+
}
1219+
}
1220+
)
1221+
1222+
impl_to_bigint!(int, FromPrimitive::from_int)
1223+
impl_to_bigint!(i8, FromPrimitive::from_i8)
1224+
impl_to_bigint!(i16, FromPrimitive::from_i16)
1225+
impl_to_bigint!(i32, FromPrimitive::from_i32)
1226+
impl_to_bigint!(i64, FromPrimitive::from_i64)
1227+
impl_to_bigint!(uint, FromPrimitive::from_uint)
1228+
impl_to_bigint!(u8, FromPrimitive::from_u8)
1229+
impl_to_bigint!(u16, FromPrimitive::from_u16)
1230+
impl_to_bigint!(u32, FromPrimitive::from_u32)
1231+
impl_to_bigint!(u64, FromPrimitive::from_u64)
1232+
11431233
impl ToStrRadix for BigInt {
11441234
#[inline]
11451235
fn to_str_radix(&self, radix: uint) -> ~str {

0 commit comments

Comments
 (0)