Skip to content

Commit 1aae28a

Browse files
committed
Replaces the free-standing functions in f32, &c.
The free-standing functions in f32, f64, i8, i16, i32, i64, u8, u16, u32, u64, float, int, and uint are replaced with generic functions in num instead. If you were previously using any of those functions, just replace them with the corresponding function with the same name in num. Note: If you were using a function that corresponds to an operator, use the operator instead.
1 parent 44770ae commit 1aae28a

35 files changed

+161
-353
lines changed

src/libextra/arena.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use list::{MutList, MutCons, MutNil};
4040
use std::at_vec;
4141
use std::cast::{transmute, transmute_mut, transmute_mut_region};
4242
use std::cast;
43+
use std::num;
4344
use std::ptr;
4445
use std::sys;
4546
use std::uint;
@@ -175,7 +176,7 @@ impl Arena {
175176
fn alloc_pod_grow(&mut self, n_bytes: uint, align: uint) -> *u8 {
176177
// Allocate a new chunk.
177178
let chunk_size = at_vec::capacity(self.pod_head.data);
178-
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
179+
let new_min_chunk_size = num::max(n_bytes, chunk_size);
179180
self.chunks = @mut MutCons(copy self.pod_head, self.chunks);
180181
self.pod_head =
181182
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), true);
@@ -217,7 +218,7 @@ impl Arena {
217218
-> (*u8, *u8) {
218219
// Allocate a new chunk.
219220
let chunk_size = at_vec::capacity(self.head.data);
220-
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
221+
let new_min_chunk_size = num::max(n_bytes, chunk_size);
221222
self.chunks = @mut MutCons(copy self.head, self.chunks);
222223
self.head =
223224
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), false);

src/libextra/bitv.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
use std::cmp;
15+
use std::num;
1516
use std::ops;
1617
use std::uint;
1718
use std::vec;
@@ -726,7 +727,7 @@ impl Set<uint> for BitvSet {
726727
}
727728
let nbits = self.capacity();
728729
if value >= nbits {
729-
let newsize = uint::max(value, nbits * 2) / uint::bits + 1;
730+
let newsize = num::max(value, nbits * 2) / uint::bits + 1;
730731
assert!(newsize > self.bitv.storage.len());
731732
self.bitv.storage.grow(newsize, &0);
732733
}
@@ -825,7 +826,7 @@ impl BitvSet {
825826
/// and w1/w2 are the words coming from the two vectors self, other.
826827
fn each_common(&self, other: &BitvSet,
827828
f: &fn(uint, uint, uint) -> bool) -> bool {
828-
let min = uint::min(self.bitv.storage.len(),
829+
let min = num::min(self.bitv.storage.len(),
829830
other.bitv.storage.len());
830831
self.bitv.storage.slice(0, min).iter().enumerate().advance(|(i, &w)| {
831832
f(i * uint::bits, w, other.bitv.storage[i])
@@ -843,7 +844,7 @@ impl BitvSet {
843844
f: &fn(bool, uint, uint) -> bool) -> bool {
844845
let len1 = self.bitv.storage.len();
845846
let len2 = other.bitv.storage.len();
846-
let min = uint::min(len1, len2);
847+
let min = num::min(len1, len2);
847848

848849
/* only one of these loops will execute and that's the point */
849850
for self.bitv.storage.slice(min, len1).iter().enumerate().advance |(i, &w)| {

src/libextra/deque.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
//! A double-ended queue implemented as a circular buffer
1212
13+
use std::num;
1314
use std::uint;
1415
use std::vec;
1516
use std::iterator::FromIterator;
@@ -51,7 +52,7 @@ impl<T> Deque<T> {
5152
/// Create an empty Deque with space for at least `n` elements.
5253
pub fn with_capacity(n: uint) -> Deque<T> {
5354
Deque{nelts: 0, lo: 0,
54-
elts: vec::from_fn(uint::max(MINIMUM_CAPACITY, n), |_| None)}
55+
elts: vec::from_fn(num::max(MINIMUM_CAPACITY, n), |_| None)}
5556
}
5657

5758
/// Return a reference to the first element in the deque

src/libextra/net/tcp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use std::comm::{stream, Port, SharedChan};
2828
use std::ptr;
2929
use std::result::{Result};
3030
use std::result;
31-
use std::uint;
31+
use std::num;
3232
use std::vec;
3333

3434
pub mod rustrt {
@@ -880,7 +880,7 @@ impl io::Reader for TcpSocketBuf {
880880
let needed = len - count;
881881
if nbuffered > 0 {
882882
unsafe {
883-
let ncopy = uint::min(nbuffered, needed);
883+
let ncopy = num::min(nbuffered, needed);
884884
let dst = ptr::mut_offset(
885885
vec::raw::to_mut_ptr(buf), count);
886886
let src = ptr::offset(

src/libextra/num/bigint.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ A BigInt is a combination of BigUint and Sign.
2121

2222
use std::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
2323
use std::int;
24+
use std::num;
2425
use std::num::{IntConvertible, Zero, One, ToStrRadix, FromStrRadix, Orderable};
2526
use std::str;
2627
use std::uint;
@@ -204,7 +205,7 @@ impl Unsigned for BigUint {}
204205
impl Add<BigUint, BigUint> for BigUint {
205206

206207
fn add(&self, other: &BigUint) -> BigUint {
207-
let new_len = uint::max(self.data.len(), other.data.len());
208+
let new_len = num::max(self.data.len(), other.data.len());
208209

209210
let mut carry = 0;
210211
let mut sum = do vec::from_fn(new_len) |i| {
@@ -224,7 +225,7 @@ impl Add<BigUint, BigUint> for BigUint {
224225
impl Sub<BigUint, BigUint> for BigUint {
225226

226227
fn sub(&self, other: &BigUint) -> BigUint {
227-
let new_len = uint::max(self.data.len(), other.data.len());
228+
let new_len = num::max(self.data.len(), other.data.len());
228229

229230
let mut borrow = 0;
230231
let diff = do vec::from_fn(new_len) |i| {
@@ -260,7 +261,7 @@ impl Mul<BigUint, BigUint> for BigUint {
260261
// = a1*b1 * base^2 +
261262
// (a1*b1 + a0*b0 - (a1-b0)*(b1-a0)) * base +
262263
// a0*b0
263-
let half_len = uint::max(s_len, o_len) / 2;
264+
let half_len = num::max(s_len, o_len) / 2;
264265
let (sHi, sLo) = cut_at(self, half_len);
265266
let (oHi, oLo) = cut_at(other, half_len);
266267

@@ -297,7 +298,7 @@ impl Mul<BigUint, BigUint> for BigUint {
297298

298299

299300
fn cut_at(a: &BigUint, n: uint) -> (BigUint, BigUint) {
300-
let mid = uint::min(a.data.len(), n);
301+
let mid = num::min(a.data.len(), n);
301302
return (BigUint::from_slice(a.data.slice(mid, a.data.len())),
302303
BigUint::from_slice(a.data.slice(0, mid)));
303304
}
@@ -482,7 +483,7 @@ impl Integer for BigUint {
482483
impl IntConvertible for BigUint {
483484

484485
fn to_int(&self) -> int {
485-
uint::min(self.to_uint(), int::max_value as uint) as int
486+
num::min(self.to_uint(), int::max_value as uint) as int
486487
}
487488

488489

@@ -580,7 +581,7 @@ impl BigUint {
580581
let mut n: BigUint = Zero::zero();
581582
let mut power: BigUint = One::one();
582583
loop {
583-
let start = uint::max(end, unit_len) - unit_len;
584+
let start = num::max(end, unit_len) - unit_len;
584585
match uint::parse_bytes(buf.slice(start, end), radix) {
585586
// FIXME(#6102): Assignment operator for BigInt causes ICE
586587
// Some(d) => n += BigUint::from_uint(d) * power,
@@ -1055,9 +1056,9 @@ impl IntConvertible for BigInt {
10551056

10561057
fn to_int(&self) -> int {
10571058
match self.sign {
1058-
Plus => uint::min(self.to_uint(), int::max_value as uint) as int,
1059+
Plus => num::min(self.to_uint(), int::max_value as uint) as int,
10591060
Zero => 0,
1060-
Minus => uint::min((-self).to_uint(),
1061+
Minus => num::min((-self).to_uint(),
10611062
(int::max_value as uint) + 1) as int
10621063
}
10631064
}

src/libextra/par.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111

1212
use std::cast;
13+
use std::num;
1314
use std::ptr;
1415
use std::sys;
15-
use std::uint;
1616
use std::vec;
1717
use future_spawn = future::spawn;
1818

@@ -44,15 +44,15 @@ fn map_slices<A:Copy + Send,B:Copy + Send>(
4444
~[f()(0u, xs)]
4545
}
4646
else {
47-
let num_tasks = uint::min(MAX_TASKS, len / MIN_GRANULARITY);
47+
let num_tasks = num::min(MAX_TASKS, len / MIN_GRANULARITY);
4848

4949
let items_per_task = len / num_tasks;
5050

5151
let mut futures = ~[];
5252
let mut base = 0u;
5353
info!("spawning tasks");
5454
while base < len {
55-
let end = uint::min(len, base + items_per_task);
55+
let end = num::min(len, base + items_per_task);
5656
do xs.as_imm_buf |p, _len| {
5757
let f = f();
5858
let base = base;

src/libextra/stats.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use sort;
1212
use std::cmp;
1313
use std::io;
1414
use std::num;
15-
use std::f64;
1615
use std::vec;
1716

1817
// NB: this can probably be rewritten in terms of num::Num
@@ -178,7 +177,7 @@ impl<'self> Stats for &'self [f64] {
178177
}
179178

180179
fn std_dev(self) -> f64 {
181-
f64::sqrt(self.var())
180+
self.var().sqrt()
182181
}
183182

184183
fn std_dev_pct(self) -> f64 {

src/libextra/time.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#[allow(missing_doc)];
1212

1313

14-
use std::i32;
1514
use std::int;
1615
use std::io;
16+
use std::num;
1717
use std::str;
1818

1919
static NSEC_PER_SEC: i32 = 1_000_000_000_i32;
@@ -249,7 +249,7 @@ impl Tm {
249249
} else {
250250
let s = self.strftime("%Y-%m-%dT%H:%M:%S");
251251
let sign = if self.tm_gmtoff > 0_i32 { '+' } else { '-' };
252-
let mut m = i32::abs(self.tm_gmtoff) / 60_i32;
252+
let mut m = num::abs(self.tm_gmtoff) / 60_i32;
253253
let h = m / 60_i32;
254254
m -= h * 60_i32;
255255
s + fmt!("%c%02d:%02d", sign, h as int, m as int)
@@ -832,7 +832,7 @@ priv fn do_strftime(format: &str, tm: &Tm) -> ~str {
832832
'Z' => copy tm.tm_zone,
833833
'z' => {
834834
let sign = if tm.tm_gmtoff > 0_i32 { '+' } else { '-' };
835-
let mut m = i32::abs(tm.tm_gmtoff) / 60_i32;
835+
let mut m = num::abs(tm.tm_gmtoff) / 60_i32;
836836
let h = m / 60_i32;
837837
m -= h * 60_i32;
838838
fmt!("%c%02d%02d", sign, h as int, m as int)

src/libextra/treemap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//! `TotalOrd`.
1414
1515

16-
use std::uint;
16+
use std::num;
1717
use std::util::{swap, replace};
1818

1919
// This is implemented as an AA tree, which is a simplified variation of
@@ -63,7 +63,7 @@ fn lt<K: Ord + TotalOrd, V: Ord>(a: &TreeMap<K, V>,
6363
let mut y = b.iter();
6464

6565
let (a_len, b_len) = (a.len(), b.len());
66-
for uint::min(a_len, b_len).times {
66+
for num::min(a_len, b_len).times {
6767
let (key_a, value_a) = x.next().unwrap();
6868
let (key_b, value_b) = y.next().unwrap();
6969
if *key_a < *key_b { return true; }

src/librustc/back/rpath.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use metadata::cstore;
1414
use metadata::filesearch;
1515

1616
use std::hashmap::HashSet;
17+
use std::num;
1718
use std::os;
1819
use std::uint;
1920
use std::util;
@@ -141,7 +142,7 @@ pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
141142
assert!(len1 > 0);
142143
assert!(len2 > 0);
143144

144-
let max_common_path = uint::min(len1, len2) - 1;
145+
let max_common_path = num::min(len1, len2) - 1;
145146
let mut start_idx = 0;
146147
while start_idx < max_common_path
147148
&& split1[start_idx] == split2[start_idx] {

src/librustc/metadata/loader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ use syntax::{ast, attr};
2525

2626
use std::cast;
2727
use std::io;
28+
use std::num;
2829
use std::option;
2930
use std::os::consts::{macos, freebsd, linux, android, win32};
3031
use std::ptr;
3132
use std::str;
32-
use std::uint;
3333
use std::vec;
3434
use extra::flate;
3535

@@ -211,7 +211,7 @@ fn get_metadata_section(os: os,
211211
let vlen = encoder::metadata_encoding_version.len();
212212
debug!("checking %u bytes of metadata-version stamp",
213213
vlen);
214-
let minsz = uint::min(vlen, csz);
214+
let minsz = num::min(vlen, csz);
215215
let mut version_ok = false;
216216
do vec::raw::buf_as_slice(cvbuf, minsz) |buf0| {
217217
version_ok = (buf0 ==

src/librustc/middle/check_match.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use middle::typeck::method_map;
1818
use middle::moves;
1919
use util::ppaux::ty_to_str;
2020

21+
use std::num;
2122
use std::uint;
2223
use std::vec;
2324
use extra::sort;
@@ -244,7 +245,7 @@ pub fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@pat]) -> useful {
244245
let max_len = do m.rev_iter().fold(0) |max_len, r| {
245246
match r[0].node {
246247
pat_vec(ref before, _, ref after) => {
247-
uint::max(before.len() + after.len(), max_len)
248+
num::max(before.len() + after.len(), max_len)
248249
}
249250
_ => max_len
250251
}

src/librustc/middle/trans/cabi_arm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use middle::trans::cabi::{ABIInfo, FnType, LLVMType};
1414

1515
use middle::trans::type_::Type;
1616

17+
use std::num;
1718
use std::option::{Option, None, Some};
18-
use std::uint;
1919

2020
fn align_up_to(off: uint, a: uint) -> uint {
2121
return (off + a - 1u) / a * a;
@@ -41,7 +41,7 @@ fn ty_align(ty: Type) -> uint {
4141
1
4242
} else {
4343
let str_tys = ty.field_types();
44-
str_tys.iter().fold(1, |a, t| uint::max(a, ty_align(*t)))
44+
str_tys.iter().fold(1, |a, t| num::max(a, ty_align(*t)))
4545
}
4646
}
4747
Array => {

src/librustc/middle/trans/cabi_mips.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
use std::libc::c_uint;
13-
use std::uint;
13+
use std::num;
1414
use std::vec;
1515
use lib::llvm::{llvm, Integer, Pointer, Float, Double, Struct, Array};
1616
use lib::llvm::{Attribute, StructRetAttribute};
@@ -43,7 +43,7 @@ fn ty_align(ty: Type) -> uint {
4343
1
4444
} else {
4545
let str_tys = ty.field_types();
46-
str_tys.iter().fold(1, |a, t| uint::max(a, ty_align(*t)))
46+
str_tys.iter().fold(1, |a, t| num::max(a, ty_align(*t)))
4747
}
4848
}
4949
Array => {
@@ -97,7 +97,7 @@ fn classify_arg_ty(ty: Type, offset: &mut uint) -> (LLVMType, Option<Attribute>)
9797
let size = ty_size(ty) * 8;
9898
let mut align = ty_align(ty);
9999

100-
align = uint::min(uint::max(align, 4), 8);
100+
align = num::min(num::max(align, 4), 8);
101101
*offset = align_up_to(*offset, align);
102102
*offset += align_up_to(size, align * 8) / 8;
103103

src/librustc/middle/trans/cabi_x86_64.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use middle::trans::cabi::*;
1818

1919
use middle::trans::type_::Type;
2020

21+
use std::num;
2122
use std::option;
2223
use std::option::Option;
2324
use std::uint;
@@ -104,7 +105,7 @@ fn classify_ty(ty: Type) -> ~[RegClass] {
104105
1
105106
} else {
106107
let str_tys = ty.field_types();
107-
str_tys.iter().fold(1, |a, t| uint::max(a, ty_align(*t)))
108+
str_tys.iter().fold(1, |a, t| num::max(a, ty_align(*t)))
108109
}
109110
}
110111
Array => {

0 commit comments

Comments
 (0)