Skip to content

Commit a544aad

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 075da9c commit a544aad

38 files changed

+171
-327
lines changed

src/libextra/arena.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ use core::uint;
4949
use core::vec;
5050
use core::unstable::intrinsics;
5151

52+
use core::num;
53+
5254
pub mod rustrt {
5355
use core::libc::size_t;
5456
use core::sys::TypeDesc;
@@ -171,7 +173,7 @@ impl Arena {
171173
fn alloc_pod_grow(&mut self, n_bytes: uint, align: uint) -> *u8 {
172174
// Allocate a new chunk.
173175
let chunk_size = at_vec::capacity(self.pod_head.data);
174-
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
176+
let new_min_chunk_size = num::max(n_bytes, chunk_size);
175177
self.chunks = @mut MutCons(copy self.pod_head, self.chunks);
176178
self.pod_head =
177179
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), true);
@@ -215,7 +217,7 @@ impl Arena {
215217
-> (*u8, *u8) {
216218
// Allocate a new chunk.
217219
let chunk_size = at_vec::capacity(self.head.data);
218-
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
220+
let new_min_chunk_size = num::max(n_bytes, chunk_size);
219221
self.chunks = @mut MutCons(copy self.head, self.chunks);
220222
self.head =
221223
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), false);

src/libextra/bitv.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use core::prelude::*;
1414

1515
use core::cmp;
16+
use core::num;
1617
use core::ops;
1718
use core::uint;
1819
use core::vec;
@@ -725,7 +726,7 @@ impl Set<uint> for BitvSet {
725726
}
726727
let nbits = self.capacity();
727728
if value >= nbits {
728-
let newsize = uint::max(value, nbits * 2) / uint::bits + 1;
729+
let newsize = num::max(value, nbits * 2) / uint::bits + 1;
729730
assert!(newsize > self.bitv.storage.len());
730731
self.bitv.storage.grow(newsize, &0);
731732
}
@@ -824,7 +825,7 @@ impl BitvSet {
824825
/// and w1/w2 are the words coming from the two vectors self, other.
825826
fn each_common(&self, other: &BitvSet,
826827
f: &fn(uint, uint, uint) -> bool) -> bool {
827-
let min = uint::min(self.bitv.storage.len(),
828+
let min = num::min(self.bitv.storage.len(),
828829
other.bitv.storage.len());
829830
self.bitv.storage.slice(0, min).eachi(|i, &w| {
830831
f(i * uint::bits, w, other.bitv.storage[i])
@@ -842,7 +843,7 @@ impl BitvSet {
842843
f: &fn(bool, uint, uint) -> bool) -> bool {
843844
let len1 = self.bitv.storage.len();
844845
let len2 = other.bitv.storage.len();
845-
let min = uint::min(len1, len2);
846+
let min = num::min(len1, len2);
846847

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

src/libextra/net_tcp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ use core::io;
2626
use core::libc::size_t;
2727
use core::libc;
2828
use core::comm::{stream, Port, SharedChan};
29+
use core::num;
2930
use core::ptr;
3031
use core::result::{Result};
3132
use core::result;
32-
use core::uint;
3333
use core::vec;
3434

3535
pub mod rustrt {
@@ -884,7 +884,7 @@ impl io::Reader for TcpSocketBuf {
884884
let needed = len - count;
885885
if nbuffered > 0 {
886886
unsafe {
887-
let ncopy = uint::min(nbuffered, needed);
887+
let ncopy = num::min(nbuffered, needed);
888888
let dst = ptr::mut_offset(
889889
vec::raw::to_mut_ptr(buf), count);
890890
let src = ptr::offset(

src/libextra/num/bigint.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use core::prelude::*;
2222
use core::iterator::IteratorUtil;
2323
use core::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
2424
use core::int;
25-
use core::num::{IntConvertible, Zero, One, ToStrRadix, FromStrRadix, Orderable};
25+
use core::num::{IntConvertible, Zero, One, ToStrRadix, FromStrRadix, Orderable, min, max};
2626
use core::str;
2727
use core::uint;
2828
use core::vec;
@@ -205,7 +205,7 @@ impl Unsigned for BigUint {}
205205
impl Add<BigUint, BigUint> for BigUint {
206206

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

210210
let mut carry = 0;
211211
let sum = do vec::from_fn(new_len) |i| {
@@ -225,7 +225,7 @@ impl Add<BigUint, BigUint> for BigUint {
225225
impl Sub<BigUint, BigUint> for BigUint {
226226

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

230230
let mut borrow = 0;
231231
let diff = do vec::from_fn(new_len) |i| {
@@ -261,7 +261,7 @@ impl Mul<BigUint, BigUint> for BigUint {
261261
// = a1*b1 * base^2 +
262262
// (a1*b1 + a0*b0 - (a1-b0)*(b1-a0)) * base +
263263
// a0*b0
264-
let half_len = uint::max(s_len, o_len) / 2;
264+
let half_len = max(s_len, o_len) / 2;
265265
let (sHi, sLo) = cut_at(self, half_len);
266266
let (oHi, oLo) = cut_at(other, half_len);
267267

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

299299

300300
fn cut_at(a: &BigUint, n: uint) -> (BigUint, BigUint) {
301-
let mid = uint::min(a.data.len(), n);
301+
let mid = min(a.data.len(), n);
302302
return (BigUint::from_slice(vec::slice(a.data, mid,
303303
a.data.len())),
304304
BigUint::from_slice(vec::slice(a.data, 0, mid)));
@@ -482,7 +482,7 @@ impl Integer for BigUint {
482482
impl IntConvertible for BigUint {
483483

484484
fn to_int(&self) -> int {
485-
uint::min(self.to_uint(), int::max_value as uint) as int
485+
min(self.to_uint(), int::max_value as uint) as int
486486
}
487487

488488

@@ -578,7 +578,7 @@ impl BigUint {
578578
let mut n: BigUint = Zero::zero();
579579
let mut power: BigUint = One::one();
580580
loop {
581-
let start = uint::max(end, unit_len) - unit_len;
581+
let start = max(end, unit_len) - unit_len;
582582
match uint::parse_bytes(vec::slice(buf, start, end), radix) {
583583
// FIXME(#6102): Assignment operator for BigInt causes ICE
584584
// Some(d) => n += BigUint::from_uint(d) * power,
@@ -1053,9 +1053,9 @@ impl IntConvertible for BigInt {
10531053

10541054
fn to_int(&self) -> int {
10551055
match self.sign {
1056-
Plus => uint::min(self.to_uint(), int::max_value as uint) as int,
1056+
Plus => min(self.to_uint(), int::max_value as uint) as int,
10571057
Zero => 0,
1058-
Minus => uint::min((-self).to_uint(),
1058+
Minus => min((-self).to_uint(),
10591059
(int::max_value as uint) + 1) as int
10601060
}
10611061
}

src/libextra/par.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use core::prelude::*;
1212

1313
use core::iterator::IteratorUtil;
1414
use core::cast;
15+
use core::num;
1516
use core::ptr;
1617
use core::sys;
17-
use core::uint;
1818
use core::vec;
1919
use future_spawn = future::spawn;
2020

@@ -46,15 +46,15 @@ fn map_slices<A:Copy + Owned,B:Copy + Owned>(
4646
~[f()(0u, xs)]
4747
}
4848
else {
49-
let num_tasks = uint::min(max_tasks, len / min_granularity);
49+
let num_tasks = num::min(max_tasks, len / min_granularity);
5050

5151
let items_per_task = len / num_tasks;
5252

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

src/libextra/rope.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ pub mod node {
567567
use core::str;
568568
use core::uint;
569569
use core::vec;
570+
use core::num;
570571

571572
/// Implementation of type `rope`
572573
pub enum Root {
@@ -1045,7 +1046,7 @@ pub mod node {
10451046
right: right,
10461047
char_len: char_len(left) + char_len(right),
10471048
byte_len: byte_len(left) + byte_len(right),
1048-
height: uint::max(height(left), height(right)) + 1u,
1049+
height: num::max(height(left), height(right)) + 1u,
10491050
})
10501051
}
10511052

src/libextra/sort.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ mod test_qsort {
842842

843843
let expected = ~[1, 2, 3];
844844

845-
do quick_sort(names) |x, y| { int::le(*x, *y) };
845+
do quick_sort(names) |x, y| { *x < *y };
846846

847847
let immut_names = names;
848848

src/libextra/stats.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use core::prelude::*;
1414

1515
use core::iterator::*;
1616
use core::vec;
17-
use core::f64;
1817
use core::cmp;
1918
use core::num;
2019
use sort;
@@ -82,7 +81,7 @@ impl<'self> Stats for &'self [f64] {
8281
}
8382

8483
fn std_dev(self) -> f64 {
85-
f64::sqrt(self.var())
84+
num::sqrt(self.var())
8685
}
8786

8887
fn std_dev_pct(self) -> f64 {

src/libextra/test.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,7 @@ pub mod bench {
699699
n = 1_000_000_000 / self.ns_per_iter();
700700
}
701701
702-
n = u64::max(u64::min(n+n/2, 100*last), last+1);
703-
n = round_up(n);
702+
n = round_up((n + n/2).clamp(&(last + 1), &(100 * last)));
704703
self.bench_n(n, f);
705704
}
706705
}

src/libextra/time.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
use core::prelude::*;
1414

15-
use core::i32;
1615
use core::int;
1716
use core::io;
17+
use core::num;
1818
use core::str;
1919
use core::iterator::IteratorUtil;
2020

@@ -251,7 +251,7 @@ impl Tm {
251251
} else {
252252
let s = self.strftime("%Y-%m-%dT%H:%M:%S");
253253
let sign = if self.tm_gmtoff > 0_i32 { '+' } else { '-' };
254-
let mut m = i32::abs(self.tm_gmtoff) / 60_i32;
254+
let mut m = num::abs(self.tm_gmtoff) / 60_i32;
255255
let h = m / 60_i32;
256256
m -= h * 60_i32;
257257
s + fmt!("%c%02d:%02d", sign, h as int, m as int)
@@ -834,7 +834,7 @@ priv fn do_strftime(format: &str, tm: &Tm) -> ~str {
834834
'Z' => copy tm.tm_zone,
835835
'z' => {
836836
let sign = if tm.tm_gmtoff > 0_i32 { '+' } else { '-' };
837-
let mut m = i32::abs(tm.tm_gmtoff) / 60_i32;
837+
let mut m = num::abs(tm.tm_gmtoff) / 60_i32;
838838
let h = m / 60_i32;
839839
m -= h * 60_i32;
840840
fmt!("%c%02d%02d", sign, h as int, m as int)

src/libextra/treemap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use core::prelude::*;
1616

1717
use core::iterator::*;
18-
use core::uint;
18+
use core::num;
1919
use core::util::{swap, replace};
2020

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

6767
let (a_len, b_len) = (a.len(), b.len());
68-
for uint::min(a_len, b_len).times {
68+
for num::min(a_len, b_len).times {
6969
let (key_a,_) = x.next().unwrap();
7070
let (key_b,_) = y.next().unwrap();
7171
if *key_a < *key_b { return true; }

src/librustc/back/rpath.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use metadata::cstore;
1515
use metadata::filesearch;
1616

1717
use core::hashmap::HashSet;
18+
use core::num;
1819
use core::os;
1920
use core::uint;
2021
use core::util;
@@ -147,7 +148,7 @@ pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
147148
assert!(len1 > 0);
148149
assert!(len2 > 0);
149150

150-
let max_common_path = uint::min(len1, len2) - 1;
151+
let max_common_path = num::min(len1, len2) - 1;
151152
let mut start_idx = 0;
152153
while start_idx < max_common_path
153154
&& split1[start_idx] == split2[start_idx] {

src/librustc/metadata/loader.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ use syntax::{ast, attr};
2626

2727
use core::cast;
2828
use core::io;
29+
use core::num;
2930
use core::option;
3031
use core::os::consts::{macos, freebsd, linux, android, win32};
3132
use core::ptr;
3233
use core::str;
33-
use core::uint;
3434
use core::vec;
3535
use extra::flate;
3636

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

src/librustc/middle/check_match.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use middle::moves;
2020
use util::ppaux::ty_to_str;
2121

2222
use core::iterator::IteratorUtil;
23+
use core::num;
2324
use core::uint;
2425
use core::vec;
2526
use extra::sort;
@@ -246,7 +247,7 @@ pub fn is_useful(cx: @MatchCheckCtxt, m: &matrix, v: &[@pat]) -> useful {
246247
let max_len = do m.rev_iter().fold(0) |max_len, r| {
247248
match r[0].node {
248249
pat_vec(ref before, _, ref after) => {
249-
uint::max(before.len() + after.len(), max_len)
250+
num::max(before.len() + after.len(), max_len)
250251
}
251252
_ => max_len
252253
}

src/librustc/middle/trans/cabi_arm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use middle::trans::common::{T_array, T_ptr, T_void};
1919

2020
use core::iterator::IteratorUtil;
2121
use core::option::{Option, None, Some};
22-
use core::uint;
22+
use core::num;
2323

2424
fn align_up_to(off: uint, a: uint) -> uint {
2525
return (off + a - 1u) / a * a;
@@ -44,7 +44,7 @@ fn ty_align(ty: TypeRef) -> uint {
4444
1
4545
} else {
4646
let str_tys = struct_tys(ty);
47-
str_tys.iter().fold(1, |a, t| uint::max(a, ty_align(*t)))
47+
str_tys.iter().fold(1, |a, t| num::max(a, ty_align(*t)))
4848
}
4949
}
5050
Array => {

src/librustc/middle/trans/cabi_mips.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use core::prelude::*;
1212

1313
use core::iterator::IteratorUtil;
1414
use core::libc::c_uint;
15+
use core::num;
1516
use core::ptr;
16-
use core::uint;
1717
use core::vec;
1818
use lib::llvm::{llvm, TypeRef, Integer, Pointer, Float, Double};
1919
use lib::llvm::{Struct, Array, Attribute};
@@ -57,7 +57,7 @@ fn ty_align(ty: TypeRef) -> uint {
5757
1
5858
} else {
5959
let str_tys = struct_tys(ty);
60-
str_tys.iter().fold(1, |a, t| uint::max(a, ty_align(*t)))
60+
str_tys.iter().fold(1, |a, t| num::max(a, ty_align(*t)))
6161
}
6262
}
6363
Array => {
@@ -113,7 +113,7 @@ fn classify_arg_ty(ty: TypeRef,
113113
let size = ty_size(ty) * 8;
114114
let mut align = ty_align(ty);
115115

116-
align = uint::min(uint::max(align, 4), 8);
116+
align = align.clamp(&4, &8);
117117
*offset = align_up_to(*offset, align);
118118
*offset += align_up_to(size, align * 8) / 8;
119119

0 commit comments

Comments
 (0)