Skip to content

Commit dc3fed0

Browse files
author
Jorge Aparicio
committed
Rename Zero variant to NoSign
1 parent 998e6c8 commit dc3fed0

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

src/bigint.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ impl ToBigUint for BigInt {
616616
fn to_biguint(&self) -> Option<BigUint> {
617617
if self.sign == Plus {
618618
Some(self.data.clone())
619-
} else if self.sign == Zero {
619+
} else if self.sign == NoSign {
620620
Some(Zero::zero())
621621
} else {
622622
None
@@ -836,15 +836,15 @@ fn get_radix_base(radix: uint) -> (DoubleBigDigit, uint) {
836836

837837
/// A Sign is a `BigInt`'s composing element.
838838
#[deriving(PartialEq, PartialOrd, Eq, Ord, Clone, Show)]
839-
pub enum Sign { Minus, Zero, Plus }
839+
pub enum Sign { Minus, NoSign, Plus }
840840

841841
impl Neg<Sign> for Sign {
842842
/// Negate Sign value.
843843
#[inline]
844844
fn neg(&self) -> Sign {
845845
match *self {
846846
Minus => Plus,
847-
Zero => Zero,
847+
NoSign => NoSign,
848848
Plus => Minus
849849
}
850850
}
@@ -880,7 +880,7 @@ impl Ord for BigInt {
880880
if scmp != Equal { return scmp; }
881881

882882
match self.sign {
883-
Zero => Equal,
883+
NoSign => Equal,
884884
Plus => self.data.cmp(&other.data),
885885
Minus => other.data.cmp(&self.data),
886886
}
@@ -931,11 +931,11 @@ impl Shr<uint, BigInt> for BigInt {
931931
impl Zero for BigInt {
932932
#[inline]
933933
fn zero() -> BigInt {
934-
BigInt::from_biguint(Zero, Zero::zero())
934+
BigInt::from_biguint(NoSign, Zero::zero())
935935
}
936936

937937
#[inline]
938-
fn is_zero(&self) -> bool { self.sign == Zero }
938+
fn is_zero(&self) -> bool { self.sign == NoSign }
939939
}
940940

941941
impl One for BigInt {
@@ -949,7 +949,7 @@ impl Signed for BigInt {
949949
#[inline]
950950
fn abs(&self) -> BigInt {
951951
match self.sign {
952-
Plus | Zero => self.clone(),
952+
Plus | NoSign => self.clone(),
953953
Minus => BigInt::from_biguint(Plus, self.data.clone())
954954
}
955955
}
@@ -964,7 +964,7 @@ impl Signed for BigInt {
964964
match self.sign {
965965
Plus => BigInt::from_biguint(Plus, One::one()),
966966
Minus => BigInt::from_biguint(Minus, One::one()),
967-
Zero => Zero::zero(),
967+
NoSign => Zero::zero(),
968968
}
969969
}
970970

@@ -979,8 +979,8 @@ impl Add<BigInt, BigInt> for BigInt {
979979
#[inline]
980980
fn add(&self, other: &BigInt) -> BigInt {
981981
match (self.sign, other.sign) {
982-
(Zero, _) => other.clone(),
983-
(_, Zero) => self.clone(),
982+
(NoSign, _) => other.clone(),
983+
(_, NoSign) => self.clone(),
984984
(Plus, Plus) => BigInt::from_biguint(Plus, self.data + other.data),
985985
(Plus, Minus) => self - (-*other),
986986
(Minus, Plus) => other - (-*self),
@@ -993,8 +993,8 @@ impl Sub<BigInt, BigInt> for BigInt {
993993
#[inline]
994994
fn sub(&self, other: &BigInt) -> BigInt {
995995
match (self.sign, other.sign) {
996-
(Zero, _) => -other,
997-
(_, Zero) => self.clone(),
996+
(NoSign, _) => -other,
997+
(_, NoSign) => self.clone(),
998998
(Plus, Plus) => match self.data.cmp(&other.data) {
999999
Less => BigInt::from_biguint(Minus, other.data - self.data),
10001000
Greater => BigInt::from_biguint(Plus, self.data - other.data),
@@ -1011,7 +1011,7 @@ impl Mul<BigInt, BigInt> for BigInt {
10111011
#[inline]
10121012
fn mul(&self, other: &BigInt) -> BigInt {
10131013
match (self.sign, other.sign) {
1014-
(Zero, _) | (_, Zero) => Zero::zero(),
1014+
(NoSign, _) | (_, NoSign) => Zero::zero(),
10151015
(Plus, Plus) | (Minus, Minus) => {
10161016
BigInt::from_biguint(Plus, self.data * other.data)
10171017
},
@@ -1085,9 +1085,9 @@ impl Integer for BigInt {
10851085
let d = BigInt::from_biguint(Plus, d_ui);
10861086
let r = BigInt::from_biguint(Plus, r_ui);
10871087
match (self.sign, other.sign) {
1088-
(_, Zero) => fail!(),
1089-
(Plus, Plus) | (Zero, Plus) => ( d, r),
1090-
(Plus, Minus) | (Zero, Minus) => (-d, r),
1088+
(_, NoSign) => fail!(),
1089+
(Plus, Plus) | (NoSign, Plus) => ( d, r),
1090+
(Plus, Minus) | (NoSign, Minus) => (-d, r),
10911091
(Minus, Plus) => (-d, -r),
10921092
(Minus, Minus) => ( d, -r)
10931093
}
@@ -1111,9 +1111,9 @@ impl Integer for BigInt {
11111111
let d = BigInt::from_biguint(Plus, d_ui);
11121112
let m = BigInt::from_biguint(Plus, m_ui);
11131113
match (self.sign, other.sign) {
1114-
(_, Zero) => fail!(),
1115-
(Plus, Plus) | (Zero, Plus) => (d, m),
1116-
(Plus, Minus) | (Zero, Minus) => if m.is_zero() {
1114+
(_, NoSign) => fail!(),
1115+
(Plus, Plus) | (NoSign, Plus) => (d, m),
1116+
(Plus, Minus) | (NoSign, Minus) => if m.is_zero() {
11171117
(-d, Zero::zero())
11181118
} else {
11191119
(-d - One::one(), m + *other)
@@ -1164,7 +1164,7 @@ impl ToPrimitive for BigInt {
11641164
fn to_i64(&self) -> Option<i64> {
11651165
match self.sign {
11661166
Plus => self.data.to_i64(),
1167-
Zero => Some(0),
1167+
NoSign => Some(0),
11681168
Minus => {
11691169
self.data.to_u64().and_then(|n| {
11701170
let m: u64 = 1 << 63;
@@ -1184,7 +1184,7 @@ impl ToPrimitive for BigInt {
11841184
fn to_u64(&self) -> Option<u64> {
11851185
match self.sign {
11861186
Plus => self.data.to_u64(),
1187-
Zero => Some(0),
1187+
NoSign => Some(0),
11881188
Minus => None
11891189
}
11901190
}
@@ -1270,7 +1270,7 @@ impl ToStrRadix for BigInt {
12701270
fn to_str_radix(&self, radix: uint) -> String {
12711271
match self.sign {
12721272
Plus => self.data.to_str_radix(radix),
1273-
Zero => "0".to_string(),
1273+
NoSign => "0".to_string(),
12741274
Minus => format!("-{}", self.data.to_str_radix(radix)),
12751275
}
12761276
}
@@ -1332,7 +1332,7 @@ impl<R: Rng> RandBigInt for R {
13321332
if self.gen() {
13331333
return self.gen_bigint(bit_size);
13341334
} else {
1335-
Zero
1335+
NoSign
13361336
}
13371337
} else if self.gen() {
13381338
Plus
@@ -1383,8 +1383,8 @@ impl BigInt {
13831383
/// The digits are be in base 2^32.
13841384
#[inline]
13851385
pub fn from_biguint(sign: Sign, data: BigUint) -> BigInt {
1386-
if sign == Zero || data.is_zero() {
1387-
return BigInt { sign: Zero, data: Zero::zero() };
1386+
if sign == NoSign || data.is_zero() {
1387+
return BigInt { sign: NoSign, data: Zero::zero() };
13881388
}
13891389
BigInt { sign: sign, data: data }
13901390
}
@@ -1413,7 +1413,7 @@ impl BigInt {
14131413
pub fn to_biguint(&self) -> Option<BigUint> {
14141414
match self.sign {
14151415
Plus => Some(self.data.clone()),
1416-
Zero => Some(Zero::zero()),
1416+
NoSign => Some(Zero::zero()),
14171417
Minus => None
14181418
}
14191419
}
@@ -2286,7 +2286,7 @@ mod biguint_tests {
22862286
mod bigint_tests {
22872287
use Integer;
22882288
use super::{BigDigit, BigUint, ToBigUint};
2289-
use super::{Sign, Minus, Zero, Plus, BigInt, RandBigInt, ToBigInt};
2289+
use super::{Sign, Minus, NoSign, Plus, BigInt, RandBigInt, ToBigInt};
22902290

22912291
use std::cmp::{Less, Equal, Greater};
22922292
use std::i64;
@@ -2305,9 +2305,9 @@ mod bigint_tests {
23052305
assert_eq!(inp, ans);
23062306
}
23072307
check(Plus, 1, Plus, 1);
2308-
check(Plus, 0, Zero, 0);
2308+
check(Plus, 0, NoSign, 0);
23092309
check(Minus, 1, Minus, 1);
2310-
check(Zero, 1, Zero, 0);
2310+
check(NoSign, 1, NoSign, 0);
23112311
}
23122312

23132313
#[test]
@@ -2355,8 +2355,8 @@ mod bigint_tests {
23552355

23562356
#[test]
23572357
fn test_hash() {
2358-
let a = BigInt::new(Zero, vec!());
2359-
let b = BigInt::new(Zero, vec!(0));
2358+
let a = BigInt::new(NoSign, vec!());
2359+
let b = BigInt::new(NoSign, vec!(0));
23602360
let c = BigInt::new(Plus, vec!(1));
23612361
let d = BigInt::new(Plus, vec!(1,0,0,0,0,0));
23622362
let e = BigInt::new(Plus, vec!(0,0,0,0,0,1));

0 commit comments

Comments
 (0)