Skip to content

Commit

Permalink
Replaces the free-standing functions in f32, &c.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
auroranockert committed Jul 8, 2013
1 parent 44770ae commit 1aae28a
Show file tree
Hide file tree
Showing 35 changed files with 161 additions and 353 deletions.
5 changes: 3 additions & 2 deletions src/libextra/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use list::{MutList, MutCons, MutNil};
use std::at_vec;
use std::cast::{transmute, transmute_mut, transmute_mut_region};
use std::cast;
use std::num;
use std::ptr;
use std::sys;
use std::uint;
Expand Down Expand Up @@ -175,7 +176,7 @@ impl Arena {
fn alloc_pod_grow(&mut self, n_bytes: uint, align: uint) -> *u8 {
// Allocate a new chunk.
let chunk_size = at_vec::capacity(self.pod_head.data);
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
let new_min_chunk_size = num::max(n_bytes, chunk_size);
self.chunks = @mut MutCons(copy self.pod_head, self.chunks);
self.pod_head =
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), true);
Expand Down Expand Up @@ -217,7 +218,7 @@ impl Arena {
-> (*u8, *u8) {
// Allocate a new chunk.
let chunk_size = at_vec::capacity(self.head.data);
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
let new_min_chunk_size = num::max(n_bytes, chunk_size);
self.chunks = @mut MutCons(copy self.head, self.chunks);
self.head =
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), false);
Expand Down
7 changes: 4 additions & 3 deletions src/libextra/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@


use std::cmp;
use std::num;
use std::ops;
use std::uint;
use std::vec;
Expand Down Expand Up @@ -726,7 +727,7 @@ impl Set<uint> for BitvSet {
}
let nbits = self.capacity();
if value >= nbits {
let newsize = uint::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 @@ -825,7 +826,7 @@ impl BitvSet {
/// and w1/w2 are the words coming from the two vectors self, other.
fn each_common(&self, other: &BitvSet,
f: &fn(uint, uint, uint) -> bool) -> bool {
let min = uint::min(self.bitv.storage.len(),
let min = num::min(self.bitv.storage.len(),
other.bitv.storage.len());
self.bitv.storage.slice(0, min).iter().enumerate().advance(|(i, &w)| {
f(i * uint::bits, w, other.bitv.storage[i])
Expand All @@ -843,7 +844,7 @@ impl BitvSet {
f: &fn(bool, uint, uint) -> bool) -> bool {
let len1 = self.bitv.storage.len();
let len2 = other.bitv.storage.len();
let min = uint::min(len1, len2);
let min = num::min(len1, len2);

/* only one of these loops will execute and that's the point */
for self.bitv.storage.slice(min, len1).iter().enumerate().advance |(i, &w)| {
Expand Down
3 changes: 2 additions & 1 deletion src/libextra/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

//! A double-ended queue implemented as a circular buffer

use std::num;
use std::uint;
use std::vec;
use std::iterator::FromIterator;
Expand Down Expand Up @@ -51,7 +52,7 @@ impl<T> Deque<T> {
/// Create an empty Deque with space for at least `n` elements.
pub fn with_capacity(n: uint) -> Deque<T> {
Deque{nelts: 0, lo: 0,
elts: vec::from_fn(uint::max(MINIMUM_CAPACITY, n), |_| None)}
elts: vec::from_fn(num::max(MINIMUM_CAPACITY, n), |_| None)}
}

/// Return a reference to the first element in the deque
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::comm::{stream, Port, SharedChan};
use std::ptr;
use std::result::{Result};
use std::result;
use std::uint;
use std::num;
use std::vec;

pub mod rustrt {
Expand Down Expand Up @@ -880,7 +880,7 @@ impl io::Reader for TcpSocketBuf {
let needed = len - count;
if nbuffered > 0 {
unsafe {
let ncopy = uint::min(nbuffered, needed);
let ncopy = num::min(nbuffered, needed);
let dst = ptr::mut_offset(
vec::raw::to_mut_ptr(buf), count);
let src = ptr::offset(
Expand Down
17 changes: 9 additions & 8 deletions src/libextra/num/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ A BigInt is a combination of BigUint and Sign.

use std::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
use std::int;
use std::num;
use std::num::{IntConvertible, Zero, One, ToStrRadix, FromStrRadix, Orderable};
use std::str;
use std::uint;
Expand Down Expand Up @@ -204,7 +205,7 @@ impl Unsigned for BigUint {}
impl Add<BigUint, BigUint> for BigUint {

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

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

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

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

Expand Down Expand Up @@ -297,7 +298,7 @@ impl Mul<BigUint, BigUint> for BigUint {


fn cut_at(a: &BigUint, n: uint) -> (BigUint, BigUint) {
let mid = uint::min(a.data.len(), n);
let mid = num::min(a.data.len(), n);
return (BigUint::from_slice(a.data.slice(mid, a.data.len())),
BigUint::from_slice(a.data.slice(0, mid)));
}
Expand Down Expand Up @@ -482,7 +483,7 @@ impl Integer for BigUint {
impl IntConvertible for BigUint {

fn to_int(&self) -> int {
uint::min(self.to_uint(), int::max_value as uint) as int
num::min(self.to_uint(), int::max_value as uint) as int
}


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

fn to_int(&self) -> int {
match self.sign {
Plus => uint::min(self.to_uint(), int::max_value as uint) as int,
Plus => num::min(self.to_uint(), int::max_value as uint) as int,
Zero => 0,
Minus => uint::min((-self).to_uint(),
Minus => num::min((-self).to_uint(),
(int::max_value as uint) + 1) as int
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/libextra/par.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@


use std::cast;
use std::num;
use std::ptr;
use std::sys;
use std::uint;
use std::vec;
use future_spawn = future::spawn;

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

let items_per_task = len / num_tasks;

let mut futures = ~[];
let mut base = 0u;
info!("spawning tasks");
while base < len {
let end = uint::min(len, base + items_per_task);
let end = num::min(len, base + items_per_task);
do xs.as_imm_buf |p, _len| {
let f = f();
let base = base;
Expand Down
3 changes: 1 addition & 2 deletions src/libextra/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use sort;
use std::cmp;
use std::io;
use std::num;
use std::f64;
use std::vec;

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

fn std_dev(self) -> f64 {
f64::sqrt(self.var())
self.var().sqrt()
}

fn std_dev_pct(self) -> f64 {
Expand Down
6 changes: 3 additions & 3 deletions src/libextra/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#[allow(missing_doc)];


use std::i32;
use std::int;
use std::io;
use std::num;
use std::str;

static NSEC_PER_SEC: i32 = 1_000_000_000_i32;
Expand Down Expand Up @@ -249,7 +249,7 @@ impl Tm {
} else {
let s = self.strftime("%Y-%m-%dT%H:%M:%S");
let sign = if self.tm_gmtoff > 0_i32 { '+' } else { '-' };
let mut m = i32::abs(self.tm_gmtoff) / 60_i32;
let mut m = num::abs(self.tm_gmtoff) / 60_i32;
let h = m / 60_i32;
m -= h * 60_i32;
s + fmt!("%c%02d:%02d", sign, h as int, m as int)
Expand Down Expand Up @@ -832,7 +832,7 @@ priv fn do_strftime(format: &str, tm: &Tm) -> ~str {
'Z' => copy tm.tm_zone,
'z' => {
let sign = if tm.tm_gmtoff > 0_i32 { '+' } else { '-' };
let mut m = i32::abs(tm.tm_gmtoff) / 60_i32;
let mut m = num::abs(tm.tm_gmtoff) / 60_i32;
let h = m / 60_i32;
m -= h * 60_i32;
fmt!("%c%02d%02d", sign, h as int, m as int)
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! `TotalOrd`.


use std::uint;
use std::num;
use std::util::{swap, replace};

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

let (a_len, b_len) = (a.len(), b.len());
for uint::min(a_len, b_len).times {
for num::min(a_len, b_len).times {
let (key_a, value_a) = x.next().unwrap();
let (key_b, value_b) = y.next().unwrap();
if *key_a < *key_b { return true; }
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use metadata::cstore;
use metadata::filesearch;

use std::hashmap::HashSet;
use std::num;
use std::os;
use std::uint;
use std::util;
Expand Down Expand Up @@ -141,7 +142,7 @@ pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
assert!(len1 > 0);
assert!(len2 > 0);

let max_common_path = uint::min(len1, len2) - 1;
let max_common_path = num::min(len1, len2) - 1;
let mut start_idx = 0;
while start_idx < max_common_path
&& split1[start_idx] == split2[start_idx] {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ use syntax::{ast, attr};

use std::cast;
use std::io;
use std::num;
use std::option;
use std::os::consts::{macos, freebsd, linux, android, win32};
use std::ptr;
use std::str;
use std::uint;
use std::vec;
use extra::flate;

Expand Down Expand Up @@ -211,7 +211,7 @@ fn get_metadata_section(os: os,
let vlen = encoder::metadata_encoding_version.len();
debug!("checking %u bytes of metadata-version stamp",
vlen);
let minsz = uint::min(vlen, csz);
let minsz = num::min(vlen, csz);
let mut version_ok = false;
do vec::raw::buf_as_slice(cvbuf, minsz) |buf0| {
version_ok = (buf0 ==
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use middle::typeck::method_map;
use middle::moves;
use util::ppaux::ty_to_str;

use std::num;
use std::uint;
use std::vec;
use extra::sort;
Expand Down Expand Up @@ -244,7 +245,7 @@ pub fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@pat]) -> useful {
let max_len = do m.rev_iter().fold(0) |max_len, r| {
match r[0].node {
pat_vec(ref before, _, ref after) => {
uint::max(before.len() + after.len(), max_len)
num::max(before.len() + after.len(), max_len)
}
_ => max_len
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/cabi_arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use middle::trans::cabi::{ABIInfo, FnType, LLVMType};

use middle::trans::type_::Type;

use std::num;
use std::option::{Option, None, Some};
use std::uint;

fn align_up_to(off: uint, a: uint) -> uint {
return (off + a - 1u) / a * a;
Expand All @@ -41,7 +41,7 @@ fn ty_align(ty: Type) -> uint {
1
} else {
let str_tys = ty.field_types();
str_tys.iter().fold(1, |a, t| uint::max(a, ty_align(*t)))
str_tys.iter().fold(1, |a, t| num::max(a, ty_align(*t)))
}
}
Array => {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/trans/cabi_mips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


use std::libc::c_uint;
use std::uint;
use std::num;
use std::vec;
use lib::llvm::{llvm, Integer, Pointer, Float, Double, Struct, Array};
use lib::llvm::{Attribute, StructRetAttribute};
Expand Down Expand Up @@ -43,7 +43,7 @@ fn ty_align(ty: Type) -> uint {
1
} else {
let str_tys = ty.field_types();
str_tys.iter().fold(1, |a, t| uint::max(a, ty_align(*t)))
str_tys.iter().fold(1, |a, t| num::max(a, ty_align(*t)))
}
}
Array => {
Expand Down Expand Up @@ -97,7 +97,7 @@ fn classify_arg_ty(ty: Type, offset: &mut uint) -> (LLVMType, Option<Attribute>)
let size = ty_size(ty) * 8;
let mut align = ty_align(ty);

align = uint::min(uint::max(align, 4), 8);
align = num::min(num::max(align, 4), 8);
*offset = align_up_to(*offset, align);
*offset += align_up_to(size, align * 8) / 8;

Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/trans/cabi_x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use middle::trans::cabi::*;

use middle::trans::type_::Type;

use std::num;
use std::option;
use std::option::Option;
use std::uint;
Expand Down Expand Up @@ -104,7 +105,7 @@ fn classify_ty(ty: Type) -> ~[RegClass] {
1
} else {
let str_tys = ty.field_types();
str_tys.iter().fold(1, |a, t| uint::max(a, ty_align(*t)))
str_tys.iter().fold(1, |a, t| num::max(a, ty_align(*t)))
}
}
Array => {
Expand Down
Loading

0 comments on commit 1aae28a

Please sign in to comment.