Skip to content

Commit 1f10ee3

Browse files
committed
Moved generic float::min, max to core::math and cleaned up some imports
1 parent 494ad4e commit 1f10ee3

File tree

11 files changed

+41
-27
lines changed

11 files changed

+41
-27
lines changed

src/comp/back/rpath.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn get_relative_to(abs1: fs::path, abs2: fs::path) -> fs::path {
129129
assert len1 > 0u;
130130
assert len2 > 0u;
131131

132-
let max_common_path = float::min(len1, len2) - 1u;
132+
let max_common_path = math::min(len1, len2) - 1u;
133133
let start_idx = 0u;
134134
while start_idx < max_common_path
135135
&& split1[start_idx] == split2[start_idx] {

src/comp/middle/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ mod unify {
17651765
let vb = alt cx.st {
17661766
in_bindings(vb) { vb }
17671767
};
1768-
ufind::grow(vb.sets, float::max(set_a, set_b) + 1u);
1768+
ufind::grow(vb.sets, math::max(set_a, set_b) + 1u);
17691769
let root_a = ufind::find(vb.sets, set_a);
17701770
let root_b = ufind::find(vb.sets, set_b);
17711771

src/comp/util/common.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import core::{str, option};
2-
import core::float::{max, min};
1+
import math::{max, min};
32
import std::map::hashmap;
43
import option::{some};
54
import syntax::ast;

src/fuzzer/fuzzer.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import core::{vec, str, int, uint, option, result};
21
import std::{fs, io};
32

43
import rustc::syntax::{ast, ast_util, fold, visit, codemap};
@@ -241,9 +240,9 @@ fn check_variants_T<copy T>(
241240
let L = vec::len(things);
242241

243242
if L < 100u {
244-
under(float::min(L, 20u)) {|i|
243+
under(math::min(L, 20u)) {|i|
245244
log(error, "Replacing... #" + uint::str(i));
246-
under(float::min(L, 30u)) {|j|
245+
under(math::min(L, 30u)) {|j|
247246
log(error, "With... " + stringifier(@things[j]));
248247
let crate2 = @replacer(crate, i, things[j], cx.mode);
249248
// It would be best to test the *crate* for stability, but testing the

src/libcore/core.rc

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export uint, u8, u32, u64, vec, bool;
1212
export either, option, result;
1313
export ctypes, sys, unsafe, comm, task;
1414
export extfmt;
15+
export math;
1516

1617
// Built-in-type support modules
1718

@@ -45,6 +46,7 @@ mod result;
4546
// Runtime and language-primitive support
4647

4748
mod ctypes;
49+
mod math;
4850
mod cmath;
4951
mod sys;
5052
mod unsafe;

src/libcore/f32.rs

+6
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,16 @@ mod consts {
224224
const ln_10: f32 = 2.30258509299404568401799145468436421_f32;
225225
}
226226

227+
pure fn signbit(x: f32) -> int {
228+
if is_negative(x) { ret 1; } else { ret 0; }
229+
}
230+
227231
#[cfg(target_os="linux")]
228232
#[cfg(target_os="macos")]
229233
#[cfg(target_os="win32")]
230234
pure fn logarithm(n: f32, b: f32) -> f32 {
235+
// FIXME check if it is good to use log2 instead of ln here;
236+
// in theory should be faster since the radix is 2
231237
ret log2(n) / log2(b);
232238
}
233239

src/libcore/f64.rs

+6
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,16 @@ mod consts {
241241
const ln_10: f64 = 2.30258509299404568401799145468436421_f64;
242242
}
243243

244+
pure fn signbit(x: f64) -> int {
245+
if is_negative(x) { ret 1; } else { ret 0; }
246+
}
247+
244248
#[cfg(target_os="linux")]
245249
#[cfg(target_os="macos")]
246250
#[cfg(target_os="win32")]
247251
pure fn logarithm(n: f64, b: f64) -> f64 {
252+
// FIXME check if it is good to use log2 instead of ln here;
253+
// in theory should be faster since the radix is 2
248254
ret log2(n) / log2(b);
249255
}
250256

src/libcore/float.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Module: float
44

55
// FIXME find out why these have to be exported explicitly
66

7-
export to_str_common, to_str_exact, to_str, from_str, min, max;
7+
export to_str_common, to_str_exact, to_str, from_str;
88
export add, sub, mul, div, rem, lt, le, gt, eq, eq, ne;
99
export is_positive, is_negative, is_nonpositive, is_nonnegative;
1010
export is_zero, is_infinite, is_finite;
@@ -16,6 +16,7 @@ export erf, erfc, exp, expm1, exp2, abs, abs_sub;
1616
export mul_add, fmax, fmin, nextafter, frexp, hypot, ldexp;
1717
export lgamma, ln, log_radix, ln1p, log10, log2, ilog_radix;
1818
export modf, pow, round, sin, sinh, sqrt, tan, tanh, tgamma, trunc;
19+
export signbit;
1920

2021
// export when m_float == c_double
2122

@@ -280,20 +281,6 @@ fn pow_uint_to_uint_as_float(x: uint, pow: uint) -> float {
280281
}
281282

282283

283-
/*
284-
Function: min
285-
286-
Returns the minimum of two values
287-
*/
288-
pure fn min<copy T>(x: T, y: T) -> T { x < y ? x : y }
289-
290-
/*
291-
Function: max
292-
293-
Returns the maximum of two values
294-
*/
295-
pure fn max<copy T>(x: T, y: T) -> T { x < y ? y : x }
296-
297284
//
298285
// Local Variables:
299286
// mode: rust

src/libcore/math.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Generic functions that have been defined for all numeric types
2+
//
3+
// (may very well go away again soon)
4+
5+
/*
6+
Function: min
7+
8+
Returns the minimum of two values
9+
*/
10+
pure fn min<copy T>(x: T, y: T) -> T { x < y ? x : y }
11+
12+
/*
13+
Function: max
14+
15+
Returns the maximum of two values
16+
*/
17+
pure fn max<copy T>(x: T, y: T) -> T { x < y ? y : x }
18+

src/libstd/rope.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ The following operations are algorithmically faster in ropes:
2626
*/
2727

2828

29-
import core::option;
30-
31-
32-
3329
/*
3430
Type: rope
3531
@@ -1103,7 +1099,7 @@ mod node {
11031099
right : right,
11041100
char_len: char_len(left) + char_len(right),
11051101
byte_len: byte_len(left) + byte_len(right),
1106-
height: float::max(height(left), height(right)) + 1u
1102+
height: math::max(height(left), height(right)) + 1u
11071103
})
11081104
}
11091105

src/test/stdtest/math.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import core::*;
22

33
use std;
44

5+
import math::{min, max};
56
import float::*;
67
import float;
78
import c_int = ctypes::c_int;

0 commit comments

Comments
 (0)