Skip to content

Uppercase numeric constants #11790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions src/libextra/bitv.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -121,8 +121,8 @@ struct BigBitv {
*/
#[inline]
fn big_mask(nbits: uint, elem: uint) -> uint {
let rmd = nbits % uint::bits;
let nelems = nbits/uint::bits + if rmd == 0 {0} else {1};
let rmd = nbits % uint::BITS;
let nelems = nbits/uint::BITS + if rmd == 0 {0} else {1};

if elem < nelems - 1 || rmd == 0 {
!0
Expand Down Expand Up @@ -192,16 +192,16 @@ impl BigBitv {

#[inline]
pub fn get(&self, i: uint) -> bool {
let w = i / uint::bits;
let b = i % uint::bits;
let w = i / uint::BITS;
let b = i % uint::BITS;
let x = 1 & self.storage[w] >> b;
x == 1
}

#[inline]
pub fn set(&mut self, i: uint, x: bool) {
let w = i / uint::bits;
let b = i % uint::bits;
let w = i / uint::BITS;
let b = i % uint::BITS;
let flag = 1 << b;
self.storage[w] = if x { self.storage[w] | flag }
else { self.storage[w] & !flag };
Expand Down Expand Up @@ -269,20 +269,20 @@ impl Bitv {

impl Bitv {
pub fn new(nbits: uint, init: bool) -> Bitv {
let rep = if nbits < uint::bits {
let rep = if nbits < uint::BITS {
Small(SmallBitv::new(if init {(1<<nbits)-1} else {0}))
} else if nbits == uint::bits {
} else if nbits == uint::BITS {
Small(SmallBitv::new(if init {!0} else {0}))
} else {
let exact = nbits % uint::bits == 0;
let nelems = nbits/uint::bits + if exact {0} else {1};
let exact = nbits % uint::BITS == 0;
let nelems = nbits/uint::BITS + if exact {0} else {1};
let s =
if init {
if exact {
vec::from_elem(nelems, !0u)
} else {
let mut v = vec::from_elem(nelems-1, !0u);
v.push((1<<nbits % uint::bits)-1);
v.push((1<<nbits % uint::BITS)-1);
v
}
} else { vec::from_elem(nelems, 0u)};
Expand Down Expand Up @@ -576,7 +576,7 @@ fn iterate_bits(base: uint, bits: uint, f: |uint| -> bool) -> bool {
if bits == 0 {
return true;
}
for i in range(0u, uint::bits) {
for i in range(0u, uint::BITS) {
if bits & (1 << i) != 0 {
if !f(base + i) {
return false;
Expand Down Expand Up @@ -680,7 +680,7 @@ impl BitvSet {

/// Returns the capacity in bits for this bit vector. Inserting any
/// element less than this amount will not trigger a resizing.
pub fn capacity(&self) -> uint { self.bitv.storage.len() * uint::bits }
pub fn capacity(&self) -> uint { self.bitv.storage.len() * uint::BITS }

/// Consumes this set to return the underlying bit vector
pub fn unwrap(self) -> Bitv {
Expand All @@ -693,7 +693,7 @@ impl BitvSet {
fn other_op(&mut self, other: &BitvSet, f: |uint, uint| -> uint) {
fn nbits(mut w: uint) -> uint {
let mut bits = 0;
for _ in range(0u, uint::bits) {
for _ in range(0u, uint::BITS) {
if w == 0 {
break;
}
Expand All @@ -703,7 +703,7 @@ impl BitvSet {
return bits;
}
if self.capacity() < other.capacity() {
self.bitv.storage.grow(other.capacity() / uint::bits, &0);
self.bitv.storage.grow(other.capacity() / uint::BITS, &0);
}
for (i, &w) in other.bitv.storage.iter().enumerate() {
let old = self.bitv.storage[i];
Expand Down Expand Up @@ -808,7 +808,7 @@ impl Mutable for BitvSet {

impl Set<uint> for BitvSet {
fn contains(&self, value: &uint) -> bool {
*value < self.bitv.storage.len() * uint::bits && self.bitv.get(*value)
*value < self.bitv.storage.len() * uint::BITS && self.bitv.get(*value)
}

fn is_disjoint(&self, other: &BitvSet) -> bool {
Expand Down Expand Up @@ -846,7 +846,7 @@ impl MutableSet<uint> for BitvSet {
}
let nbits = self.capacity();
if value >= nbits {
let newsize = num::max(value, nbits * 2) / uint::bits + 1;
let newsize = num::max(value, nbits * 2) / uint::BITS + 1;
assert!(newsize > self.bitv.storage.len());
self.bitv.storage.grow(newsize, &0);
}
Expand Down Expand Up @@ -884,7 +884,7 @@ impl BitvSet {
let min = num::min(self.bitv.storage.len(), other.bitv.storage.len());
self.bitv.storage.slice(0, min).iter().enumerate()
.zip(Repeat::new(&other.bitv.storage))
.map(|((i, &w), o_store)| (i * uint::bits, w, o_store[i]))
.map(|((i, &w), o_store)| (i * uint::BITS, w, o_store[i]))
}

/// Visits each word in `self` or `other` that extends beyond the other. This
Expand All @@ -903,11 +903,11 @@ impl BitvSet {
if olen < slen {
self.bitv.storage.slice_from(olen).iter().enumerate()
.zip(Repeat::new(olen))
.map(|((i, &w), min)| (true, (i + min) * uint::bits, w))
.map(|((i, &w), min)| (true, (i + min) * uint::BITS, w))
} else {
other.bitv.storage.slice_from(slen).iter().enumerate()
.zip(Repeat::new(slen))
.map(|((i, &w), min)| (false, (i + min) * uint::bits, w))
.map(|((i, &w), min)| (false, (i + min) * uint::BITS, w))
}
}
}
Expand Down Expand Up @@ -1529,7 +1529,7 @@ mod tests {

assert!(a.insert(1000));
assert!(a.remove(&1000));
assert_eq!(a.capacity(), uint::bits);
assert_eq!(a.capacity(), uint::BITS);
}

#[test]
Expand Down Expand Up @@ -1561,16 +1561,16 @@ mod tests {
let mut r = rng();
let mut bitv = 0 as uint;
b.iter(|| {
bitv |= (1 << ((r.next_u32() as uint) % uint::bits));
bitv |= (1 << ((r.next_u32() as uint) % uint::BITS));
})
}

#[bench]
fn bench_small_bitv_small(b: &mut BenchHarness) {
let mut r = rng();
let mut bitv = SmallBitv::new(uint::bits);
let mut bitv = SmallBitv::new(uint::BITS);
b.iter(|| {
bitv.set((r.next_u32() as uint) % uint::bits, true);
bitv.set((r.next_u32() as uint) % uint::BITS, true);
})
}

Expand All @@ -1579,15 +1579,15 @@ mod tests {
let mut r = rng();
let mut bitv = BigBitv::new(~[0]);
b.iter(|| {
bitv.set((r.next_u32() as uint) % uint::bits, true);
bitv.set((r.next_u32() as uint) % uint::BITS, true);
})
}

#[bench]
fn bench_big_bitv_big(b: &mut BenchHarness) {
let mut r = rng();
let mut storage = ~[];
storage.grow(BENCH_BITS / uint::bits, &0u);
storage.grow(BENCH_BITS / uint::BITS, &0u);
let mut bitv = BigBitv::new(storage);
b.iter(|| {
bitv.set((r.next_u32() as uint) % BENCH_BITS, true);
Expand All @@ -1606,9 +1606,9 @@ mod tests {
#[bench]
fn bench_bitv_small(b: &mut BenchHarness) {
let mut r = rng();
let mut bitv = Bitv::new(uint::bits, false);
let mut bitv = Bitv::new(uint::BITS, false);
b.iter(|| {
bitv.set((r.next_u32() as uint) % uint::bits, true);
bitv.set((r.next_u32() as uint) % uint::BITS, true);
})
}

Expand All @@ -1617,7 +1617,7 @@ mod tests {
let mut r = rng();
let mut bitv = BitvSet::new();
b.iter(|| {
bitv.insert((r.next_u32() as uint) % uint::bits);
bitv.insert((r.next_u32() as uint) % uint::BITS);
})
}

Expand All @@ -1641,7 +1641,7 @@ mod tests {

#[bench]
fn bench_btv_small_iter(b: &mut BenchHarness) {
let bitv = Bitv::new(uint::bits, false);
let bitv = Bitv::new(uint::BITS, false);
b.iter(|| {
let mut _sum = 0;
for pres in bitv.iter() {
Expand Down
6 changes: 3 additions & 3 deletions src/libextra/ebml.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -364,7 +364,7 @@ pub mod reader {
fn read_u8 (&mut self) -> u8 { doc_as_u8 (self.next_doc(EsU8 )) }
fn read_uint(&mut self) -> uint {
let v = doc_as_u64(self.next_doc(EsUint));
if v > (::std::uint::max_value as u64) {
if v > (::std::uint::MAX as u64) {
fail!("uint {} too large for this architecture", v);
}
v as uint
Expand All @@ -384,7 +384,7 @@ pub mod reader {
}
fn read_int(&mut self) -> int {
let v = doc_as_u64(self.next_doc(EsInt)) as i64;
if v > (int::max_value as i64) || v < (int::min_value as i64) {
if v > (int::MAX as i64) || v < (int::MIN as i64) {
debug!("FIXME \\#6122: Removing this makes this function miscompile");
fail!("int {} out of range for this architecture", v);
}
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/getopts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -848,7 +848,7 @@ pub mod groups {
t("hello", 15, [~"hello"]);
t("\nMary had a little lamb\nLittle lamb\n", 15,
[~"Mary had a", ~"little lamb", ~"Little lamb"]);
t("\nMary had a little lamb\nLittle lamb\n", ::std::uint::max_value,
t("\nMary had a little lamb\nLittle lamb\n", ::std::uint::MAX,
[~"Mary had a little lamb\nLittle lamb"]);
}
} // end groups module
Expand Down
42 changes: 21 additions & 21 deletions src/libextra/num/bigint.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -1186,7 +1186,7 @@ impl ToPrimitive for BigInt {
if n < m {
Some(-(n as i64))
} else if n == m {
Some(i64::min_value)
Some(i64::MIN)
} else {
None
}
Expand All @@ -1213,7 +1213,7 @@ impl FromPrimitive for BigInt {
Some(BigInt::from_biguint(Plus, n))
})
} else if n < 0 {
FromPrimitive::from_u64(u64::max_value - (n as u64) + 1).and_then(
FromPrimitive::from_u64(u64::MAX - (n as u64) + 1).and_then(
|n| {
Some(BigInt::from_biguint(Minus, n))
})
Expand Down Expand Up @@ -1625,7 +1625,7 @@ mod biguint_tests {

check(Zero::zero(), 0);
check(One::one(), 1);
check(i64::max_value.to_biguint().unwrap(), i64::max_value);
check(i64::MAX.to_biguint().unwrap(), i64::MAX);

check(BigUint::new(~[ ]), 0);
check(BigUint::new(~[ 1 ]), (1 << (0*BigDigit::bits)));
Expand All @@ -1635,9 +1635,9 @@ mod biguint_tests {
check(BigUint::new(~[ 0, 0, 1 ]), (1 << (2*BigDigit::bits)));
check(BigUint::new(~[-1, -1, -1 ]), (1 << (3*BigDigit::bits)) - 1);
check(BigUint::new(~[ 0, 0, 0, 1 ]), (1 << (3*BigDigit::bits)));
check(BigUint::new(~[-1, -1, -1, -1 >> 1]), i64::max_value);
check(BigUint::new(~[-1, -1, -1, -1 >> 1]), i64::MAX);

assert_eq!(i64::min_value.to_biguint(), None);
assert_eq!(i64::MIN.to_biguint(), None);
assert_eq!(BigUint::new(~[-1, -1, -1, -1 ]).to_i64(), None);
assert_eq!(BigUint::new(~[ 0, 0, 0, 0, 1]).to_i64(), None);
assert_eq!(BigUint::new(~[-1, -1, -1, -1, -1]).to_i64(), None);
Expand All @@ -1654,15 +1654,15 @@ mod biguint_tests {

check(Zero::zero(), 0);
check(One::one(), 1);
check(i64::max_value.to_biguint().unwrap(), i64::max_value);
check(i64::MAX.to_biguint().unwrap(), i64::MAX);

check(BigUint::new(~[ ]), 0);
check(BigUint::new(~[ 1 ]), (1 << (0*BigDigit::bits)));
check(BigUint::new(~[-1 ]), (1 << (1*BigDigit::bits)) - 1);
check(BigUint::new(~[ 0, 1 ]), (1 << (1*BigDigit::bits)));
check(BigUint::new(~[-1, -1 >> 1]), i64::max_value);
check(BigUint::new(~[-1, -1 >> 1]), i64::MAX);

assert_eq!(i64::min_value.to_biguint(), None);
assert_eq!(i64::MIN.to_biguint(), None);
assert_eq!(BigUint::new(~[-1, -1 ]).to_i64(), None);
assert_eq!(BigUint::new(~[ 0, 0, 1]).to_i64(), None);
assert_eq!(BigUint::new(~[-1, -1, -1]).to_i64(), None);
Expand All @@ -1679,8 +1679,8 @@ mod biguint_tests {

check(Zero::zero(), 0);
check(One::one(), 1);
check(u64::min_value.to_biguint().unwrap(), u64::min_value);
check(u64::max_value.to_biguint().unwrap(), u64::max_value);
check(u64::MIN.to_biguint().unwrap(), u64::MIN);
check(u64::MAX.to_biguint().unwrap(), u64::MAX);

check(BigUint::new(~[ ]), 0);
check(BigUint::new(~[ 1 ]), (1 << (0*BigDigit::bits)));
Expand All @@ -1690,7 +1690,7 @@ mod biguint_tests {
check(BigUint::new(~[ 0, 0, 1 ]), (1 << (2*BigDigit::bits)));
check(BigUint::new(~[-1, -1, -1 ]), (1 << (3*BigDigit::bits)) - 1);
check(BigUint::new(~[ 0, 0, 0, 1]), (1 << (3*BigDigit::bits)));
check(BigUint::new(~[-1, -1, -1, -1]), u64::max_value);
check(BigUint::new(~[-1, -1, -1, -1]), u64::MAX);

assert_eq!(BigUint::new(~[ 0, 0, 0, 0, 1]).to_u64(), None);
assert_eq!(BigUint::new(~[-1, -1, -1, -1, -1]).to_u64(), None);
Expand All @@ -1707,14 +1707,14 @@ mod biguint_tests {

check(Zero::zero(), 0);
check(One::one(), 1);
check(u64::min_value.to_biguint().unwrap(), u64::min_value);
check(u64::max_value.to_biguint().unwrap(), u64::max_value);
check(u64::MIN.to_biguint().unwrap(), u64::MIN);
check(u64::MAX.to_biguint().unwrap(), u64::MAX);

check(BigUint::new(~[ ]), 0);
check(BigUint::new(~[ 1 ]), (1 << (0*BigDigit::bits)));
check(BigUint::new(~[-1 ]), (1 << (1*BigDigit::bits)) - 1);
check(BigUint::new(~[ 0, 1]), (1 << (1*BigDigit::bits)));
check(BigUint::new(~[-1, -1]), u64::max_value);
check(BigUint::new(~[-1, -1]), u64::MAX);

assert_eq!(BigUint::new(~[ 0, 0, 1]).to_u64(), None);
assert_eq!(BigUint::new(~[-1, -1, -1]).to_u64(), None);
Expand Down Expand Up @@ -2166,11 +2166,11 @@ mod bigint_tests {

check(Zero::zero(), 0);
check(One::one(), 1);
check(i64::min_value.to_bigint().unwrap(), i64::min_value);
check(i64::max_value.to_bigint().unwrap(), i64::max_value);
check(i64::MIN.to_bigint().unwrap(), i64::MIN);
check(i64::MAX.to_bigint().unwrap(), i64::MAX);

assert_eq!(
(i64::max_value as u64 + 1).to_bigint().unwrap().to_i64(),
(i64::MAX as u64 + 1).to_bigint().unwrap().to_i64(),
None);

assert_eq!(
Expand All @@ -2196,14 +2196,14 @@ mod bigint_tests {

check(Zero::zero(), 0);
check(One::one(), 1);
check(u64::min_value.to_bigint().unwrap(), u64::min_value);
check(u64::max_value.to_bigint().unwrap(), u64::max_value);
check(u64::MIN.to_bigint().unwrap(), u64::MIN);
check(u64::MAX.to_bigint().unwrap(), u64::MAX);

assert_eq!(
BigInt::from_biguint(Plus, BigUint::new(~[1, 2, 3, 4, 5])).to_u64(),
None);

let max_value: BigUint = FromPrimitive::from_u64(u64::max_value).unwrap();
let max_value: BigUint = FromPrimitive::from_u64(u64::MAX).unwrap();
assert_eq!(BigInt::from_biguint(Minus, max_value).to_u64(), None);
assert_eq!(BigInt::from_biguint(Minus, BigUint::new(~[1, 2, 3, 4, 5])).to_u64(), None);
}
Expand Down
Loading