auto merge of #7117 : jensnockert/rust/freestanding, r=cmr

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.

This means that instead of having to know everywhere what the type is, like

~~~
f64::sin(x)
~~~

You can simply write code that uses the type-generic versions in num instead, this works for all types that implement the corresponding trait in num.

~~~
num::sin(x)
~~~

Note 1: If you were previously using any of those functions, just replace them
with the corresponding function with the same name in num.

Note 2: If you were using a function that corresponds to an operator, use the
operator instead.

Note 3: This is just https://github.com/mozilla/rust/pull/7090 reopened against master.
This commit is contained in:
bors 2013-07-09 13:34:50 -07:00
commit e388a80c23
41 changed files with 178 additions and 376 deletions

View file

@ -802,11 +802,11 @@ Use declarations support a number of convenient shortcuts:
An example of `use` declarations:
~~~~
use std::float::sin;
use std::num::sin;
use std::option::{Some, None};
fn main() {
// Equivalent to 'info!(std::float::sin(1.0));'
// Equivalent to 'info!(std::num::sin(1.0));'
info!(sin(1.0));
// Equivalent to 'info!(~[std::option::Some(1.0), std::option::None]);'

View file

@ -503,12 +503,13 @@ types.
~~~~
# use std::float;
# use std::num::atan;
fn angle(vector: (float, float)) -> float {
let pi = float::consts::pi;
match vector {
(0f, y) if y < 0f => 1.5 * pi,
(0f, y) => 0.5 * pi,
(x, y) => float::atan(y / x)
(x, y) => atan(y / x)
}
}
~~~~
@ -1728,10 +1729,9 @@ To call such a method, just prefix it with the type name and a double colon:
~~~~
# use std::float::consts::pi;
# use std::float::sqrt;
struct Circle { radius: float }
impl Circle {
fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
fn new(area: float) -> Circle { Circle { radius: (area / pi).sqrt() } }
}
let c = Circle::new(42.5);
~~~~
@ -1997,16 +1997,15 @@ implementation to use.
~~~~
# use std::float::consts::pi;
# use std::float::sqrt;
trait Shape { fn new(area: float) -> Self; }
struct Circle { radius: float }
struct Square { length: float }
impl Shape for Circle {
fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
fn new(area: float) -> Circle { Circle { radius: (area / pi).sqrt() } }
}
impl Shape for Square {
fn new(area: float) -> Square { Square { length: sqrt(area) } }
fn new(area: float) -> Square { Square { length: (area).sqrt() } }
}
let area = 42.5;
@ -2154,14 +2153,13 @@ Now, we can implement `Circle` on a type only if we also implement `Shape`.
~~~~
# use std::float::consts::pi;
# use std::float::sqrt;
# trait Shape { fn area(&self) -> float; }
# trait Circle : Shape { fn radius(&self) -> float; }
# struct Point { x: float, y: float }
# fn square(x: float) -> float { x * x }
struct CircleStruct { center: Point, radius: float }
impl Circle for CircleStruct {
fn radius(&self) -> float { sqrt(self.area() / pi) }
fn radius(&self) -> float { (self.area() / pi).sqrt() }
}
impl Shape for CircleStruct {
fn area(&self) -> float { pi * square(self.radius) }
@ -2190,12 +2188,11 @@ Likewise, supertrait methods may also be called on trait objects.
~~~ {.xfail-test}
# use std::float::consts::pi;
# use std::float::sqrt;
# trait Shape { fn area(&self) -> float; }
# trait Circle : Shape { fn radius(&self) -> float; }
# struct Point { x: float, y: float }
# struct CircleStruct { center: Point, radius: float }
# impl Circle for CircleStruct { fn radius(&self) -> float { sqrt(self.area() / pi) } }
# impl Circle for CircleStruct { fn radius(&self) -> float { (self.area() / pi).sqrt() } }
# impl Shape for CircleStruct { fn area(&self) -> float { pi * square(self.radius) } }
let concrete = @CircleStruct{center:Point{x:3f,y:4f},radius:5f};

View file

@ -40,6 +40,7 @@
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;
@ -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);
@ -217,7 +218,7 @@ fn alloc_nonpod_grow(&mut self, n_bytes: uint, align: uint)
-> (*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);

View file

@ -12,6 +12,7 @@
use std::cmp;
use std::num;
use std::ops;
use std::uint;
use std::vec;
@ -726,7 +727,7 @@ fn insert(&mut self, value: uint) -> bool {
}
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);
}
@ -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])
@ -843,7 +844,7 @@ fn each_outlier(&self, other: &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)| {

View file

@ -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;
@ -51,7 +52,7 @@ pub fn new() -> 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

View file

@ -28,7 +28,7 @@
use std::ptr;
use std::result::{Result};
use std::result;
use std::uint;
use std::num;
use std::vec;
pub mod rustrt {
@ -880,7 +880,7 @@ fn read(&self, buf: &mut [u8], len: uint) -> uint {
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(

View file

@ -21,6 +21,7 @@
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;
@ -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| {
@ -224,7 +225,7 @@ fn add(&self, other: &BigUint) -> 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| {
@ -260,7 +261,7 @@ fn mul(&self, other: &BigUint) -> 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);
@ -297,7 +298,7 @@ fn mul_digit(a: &BigUint, n: BigDigit) -> 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)));
}
@ -482,7 +483,7 @@ fn is_odd(&self) -> bool { !self.is_even() }
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
}
@ -580,7 +581,7 @@ pub fn parse_bytes(buf: &[u8], radix: uint)
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,
@ -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
}
}

View file

@ -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;
@ -44,7 +44,7 @@ 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;
@ -52,7 +52,7 @@ fn map_slices<A:Copy + Send,B:Copy + Send>(
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;

View file

@ -840,7 +840,7 @@ fn test_simple() {
let expected = ~[1, 2, 3];
do quick_sort(names) |x, y| { int::le(*x, *y) };
do quick_sort(names) |x, y| { *x < *y };
let immut_names = names;

View file

@ -12,7 +12,6 @@
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
@ -178,7 +177,7 @@ fn var(self) -> f64 {
}
fn std_dev(self) -> f64 {
f64::sqrt(self.var())
self.var().sqrt()
}
fn std_dev_pct(self) -> f64 {

View file

@ -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;
@ -249,7 +249,7 @@ pub fn rfc3339(&self) -> ~str {
} 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)
@ -832,7 +832,7 @@ fn parse_type(ch: char, 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)

View file

@ -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
@ -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; }

View file

@ -14,6 +14,7 @@
use metadata::filesearch;
use std::hashmap::HashSet;
use std::num;
use std::os;
use std::uint;
use std::util;
@ -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] {

View file

@ -25,11 +25,11 @@
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;
@ -213,7 +213,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 ==

View file

@ -18,6 +18,7 @@
use middle::moves;
use util::ppaux::ty_to_str;
use std::num;
use std::uint;
use std::vec;
use extra::sort;
@ -234,7 +235,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
}

View file

@ -14,8 +14,8 @@
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;
@ -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 => {

View file

@ -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};
@ -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 => {
@ -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;

View file

@ -18,6 +18,7 @@
use middle::trans::type_::Type;
use std::num;
use std::option;
use std::option::Option;
use std::uint;
@ -104,7 +105,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 => {

View file

@ -34,11 +34,11 @@
use middle::lint;
use std::io;
use std::num;
use std::os;
use std::result;
use std::str;
use std::task;
use std::uint;
use std::vec;
use extra::getopts::{groups, opt_present};
use extra::getopts;
@ -153,7 +153,7 @@ pub fn describe_warnings() {
let lint_dict = lint::get_lint_dict();
let mut max_key = 0;
for lint_dict.each_key |k| { max_key = uint::max(k.len(), max_key); }
for lint_dict.each_key |k| { max_key = num::max(k.len(), max_key); }
fn padded(max: uint, s: &str) -> ~str {
str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s
}

View file

@ -20,6 +20,7 @@
*/
use std::num;
use std::uint;
use pass::Pass;
use text_pass;
@ -69,7 +70,7 @@ fn unindent(s: &str) -> ~str {
false
}
};
uint::min(min_indent, spaces)
num::min(min_indent, spaces)
}
};

View file

@ -19,6 +19,7 @@
use cmp::{Eq, Equiv};
use hash::Hash;
use iterator::{Iterator, IteratorUtil};
use num;
use option::{None, Option, Some};
use rand::RngUtil;
use rand;
@ -74,7 +75,7 @@ pub fn linear_map_with_capacity<K:Eq + Hash,V>(
fn linear_map_with_capacity_and_keys<K:Eq + Hash,V>(
k0: u64, k1: u64,
initial_capacity: uint) -> HashMap<K, V> {
let cap = uint::max(INITIAL_CAPACITY, initial_capacity);
let cap = num::max(INITIAL_CAPACITY, initial_capacity);
HashMap {
k0: k0, k1: k1,
resize_at: resize_at(cap),

View file

@ -53,6 +53,7 @@
use libc;
use libc::{c_int, c_long, c_void, size_t, ssize_t};
use libc::consts::os::posix88::*;
use num;
use os;
use cast;
use path::Path;
@ -1054,7 +1055,7 @@ pub struct BytesReader {
impl Reader for BytesReader {
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
let count = uint::min(len, self.bytes.len() - *self.pos);
let count = num::min(len, self.bytes.len() - *self.pos);
let view = self.bytes.slice(*self.pos, self.bytes.len());
vec::bytes::copy_memory(bytes, view, count);
@ -1660,7 +1661,7 @@ fn write(&self, v: &[u8]) {
let v_len = v.len();
let bytes = &mut *self.bytes;
let count = uint::max(bytes.len(), *self.pos + v_len);
let count = num::max(bytes.len(), *self.pos + v_len);
bytes.reserve(count);
unsafe {

View file

@ -21,9 +21,7 @@
pub use cmath::c_float_targ_consts::*;
// An inner module is required to get the #[inline] attribute on the
// functions.
pub use self::delegated::*;
use self::delegated::*;
macro_rules! delegate(
(
@ -35,6 +33,8 @@ fn $name:ident(
) -> $rv:ty = $bound_name:path
),*
) => (
// An inner module is required to get the #[inline] attribute on the
// functions.
mod delegated {
use cmath::c_float_utils;
use libc::{c_float, c_int};
@ -116,50 +116,6 @@ fn tgamma(n: c_float) -> c_float = c_float_utils::tgamma
pub static neg_infinity: f32 = -1.0_f32/0.0_f32;
#[inline]
pub fn add(x: f32, y: f32) -> f32 { return x + y; }
#[inline]
pub fn sub(x: f32, y: f32) -> f32 { return x - y; }
#[inline]
pub fn mul(x: f32, y: f32) -> f32 { return x * y; }
#[inline]
pub fn div(x: f32, y: f32) -> f32 { return x / y; }
#[inline]
pub fn rem(x: f32, y: f32) -> f32 { return x % y; }
#[inline]
pub fn lt(x: f32, y: f32) -> bool { return x < y; }
#[inline]
pub fn le(x: f32, y: f32) -> bool { return x <= y; }
#[inline]
pub fn eq(x: f32, y: f32) -> bool { return x == y; }
#[inline]
pub fn ne(x: f32, y: f32) -> bool { return x != y; }
#[inline]
pub fn ge(x: f32, y: f32) -> bool { return x >= y; }
#[inline]
pub fn gt(x: f32, y: f32) -> bool { return x > y; }
#[inline]
pub fn fmax(x: f32, y: f32) -> f32 {
if x >= y || y.is_NaN() { x } else { y }
}
#[inline]
pub fn fmin(x: f32, y: f32) -> f32 {
if x <= y || y.is_NaN() { x } else { y }
}
// FIXME (#1999): replace the predicates below with llvm intrinsics or
// calls to the libmath macros in the rust runtime for performance.
@ -251,13 +207,23 @@ impl Orderable for f32 {
/// Returns `NaN` if either of the numbers are `NaN`.
#[inline]
fn min(&self, other: &f32) -> f32 {
if self.is_NaN() || other.is_NaN() { Float::NaN() } else { fmin(*self, *other) }
cond!(
(self.is_NaN()) { *self }
(other.is_NaN()) { *other }
(*self < *other) { *self }
_ { *other }
)
}
/// Returns `NaN` if either of the numbers are `NaN`.
#[inline]
fn max(&self, other: &f32) -> f32 {
if self.is_NaN() || other.is_NaN() { Float::NaN() } else { fmax(*self, *other) }
cond!(
(self.is_NaN()) { *self }
(other.is_NaN()) { *other }
(*self > *other) { *self }
_ { *other }
)
}
/// Returns the number constrained within the range `mn <= self <= mx`.

View file

@ -23,9 +23,7 @@
pub use cmath::c_double_targ_consts::*;
pub use cmp::{min, max};
// An inner module is required to get the #[inline] attribute on the
// functions.
pub use self::delegated::*;
use self::delegated::*;
macro_rules! delegate(
(
@ -37,6 +35,8 @@ fn $name:ident(
) -> $rv:ty = $bound_name:path
),*
) => (
// An inner module is required to get the #[inline] attribute on the
// functions.
mod delegated {
use cmath::c_double_utils;
use libc::{c_double, c_int};
@ -142,49 +142,6 @@ fn yn(i: c_int, n: c_double) -> c_double = c_double_utils::yn
pub static neg_infinity: f64 = -1.0_f64/0.0_f64;
#[inline]
pub fn add(x: f64, y: f64) -> f64 { return x + y; }
#[inline]
pub fn sub(x: f64, y: f64) -> f64 { return x - y; }
#[inline]
pub fn mul(x: f64, y: f64) -> f64 { return x * y; }
#[inline]
pub fn div(x: f64, y: f64) -> f64 { return x / y; }
#[inline]
pub fn rem(x: f64, y: f64) -> f64 { return x % y; }
#[inline]
pub fn lt(x: f64, y: f64) -> bool { return x < y; }
#[inline]
pub fn le(x: f64, y: f64) -> bool { return x <= y; }
#[inline]
pub fn eq(x: f64, y: f64) -> bool { return x == y; }
#[inline]
pub fn ne(x: f64, y: f64) -> bool { return x != y; }
#[inline]
pub fn ge(x: f64, y: f64) -> bool { return x >= y; }
#[inline]
pub fn gt(x: f64, y: f64) -> bool { return x > y; }
#[inline]
pub fn fmax(x: f64, y: f64) -> f64 {
if x >= y || y.is_NaN() { x } else { y }
}
#[inline]
pub fn fmin(x: f64, y: f64) -> f64 {
if x <= y || y.is_NaN() { x } else { y }
}
// FIXME (#1999): add is_normal, is_subnormal, and fpclassify
/* Module: consts */
@ -273,13 +230,23 @@ impl Orderable for f64 {
/// Returns `NaN` if either of the numbers are `NaN`.
#[inline]
fn min(&self, other: &f64) -> f64 {
if self.is_NaN() || other.is_NaN() { Float::NaN() } else { fmin(*self, *other) }
cond!(
(self.is_NaN()) { *self }
(other.is_NaN()) { *other }
(*self < *other) { *self }
_ { *other }
)
}
/// Returns `NaN` if either of the numbers are `NaN`.
#[inline]
fn max(&self, other: &f64) -> f64 {
if self.is_NaN() || other.is_NaN() { Float::NaN() } else { fmax(*self, *other) }
cond!(
(self.is_NaN()) { *self }
(other.is_NaN()) { *other }
(*self > *other) { *self }
_ { *other }
)
}
/// Returns the number constrained within the range `mn <= self <= mx`.

View file

@ -23,22 +23,12 @@
#[allow(missing_doc)];
#[allow(non_uppercase_statics)];
use f64;
use libc::c_int;
use num::{Zero, One, strconv};
use num::FPCategory;
use num;
use prelude::*;
use to_str;
pub use f64::{add, sub, mul, div, rem, lt, le, eq, ne, ge, gt};
pub use f64::{acos, asin, atan2, cbrt, ceil, copysign, cosh, floor};
pub use f64::{erf, erfc, exp, exp_m1, exp2, abs_sub};
pub use f64::{mul_add, fmax, fmin, next_after, frexp, hypot, ldexp};
pub use f64::{lgamma, ln, log_radix, ln_1p, log10, log2, ilog_radix};
pub use f64::{modf, pow, powi, round, sinh, tanh, tgamma, trunc};
pub use f64::{j0, j1, jn, y0, y1, yn};
pub static NaN: float = 0.0/0.0;
pub static infinity: float = 1.0/0.0;
@ -342,31 +332,6 @@ pub fn pow_with_uint(base: uint, pow: uint) -> float {
return total;
}
#[inline]
pub fn abs(x: float) -> float {
f64::abs(x as f64) as float
}
#[inline]
pub fn sqrt(x: float) -> float {
f64::sqrt(x as f64) as float
}
#[inline]
pub fn atan(x: float) -> float {
f64::atan(x as f64) as float
}
#[inline]
pub fn sin(x: float) -> float {
f64::sin(x as f64) as float
}
#[inline]
pub fn cos(x: float) -> float {
f64::cos(x as f64) as float
}
#[inline]
pub fn tan(x: float) -> float {
f64::tan(x as f64) as float
}
impl Num for float {}
#[cfg(not(test))]
@ -443,19 +408,19 @@ fn one() -> float { 1.0 }
impl Round for float {
/// Round half-way cases toward `neg_infinity`
#[inline]
fn floor(&self) -> float { floor(*self as f64) as float }
fn floor(&self) -> float { (*self as f64).floor() as float }
/// Round half-way cases toward `infinity`
#[inline]
fn ceil(&self) -> float { ceil(*self as f64) as float }
fn ceil(&self) -> float { (*self as f64).ceil() as float }
/// Round half-way cases away from `0.0`
#[inline]
fn round(&self) -> float { round(*self as f64) as float }
fn round(&self) -> float { (*self as f64).round() as float }
/// The integer part of the number (rounds towards `0.0`)
#[inline]
fn trunc(&self) -> float { trunc(*self as f64) as float }
fn trunc(&self) -> float { (*self as f64).trunc() as float }
///
/// The fractional part of the number, satisfying:
@ -727,31 +692,30 @@ fn to_radians(&self) -> float { (*self as f64).to_radians() as float }
impl RealExt for float {
#[inline]
fn lgamma(&self) -> (int, float) {
let mut sign = 0;
let result = lgamma(*self as f64, &mut sign);
(sign as int, result as float)
let (sign, value) = (*self as f64).lgamma();
(sign, value as float)
}
#[inline]
fn tgamma(&self) -> float { tgamma(*self as f64) as float }
fn tgamma(&self) -> float { (*self as f64).tgamma() as float }
#[inline]
fn j0(&self) -> float { j0(*self as f64) as float }
fn j0(&self) -> float { (*self as f64).j0() as float }
#[inline]
fn j1(&self) -> float { j1(*self as f64) as float }
fn j1(&self) -> float { (*self as f64).j1() as float }
#[inline]
fn jn(&self, n: int) -> float { jn(n as c_int, *self as f64) as float }
fn jn(&self, n: int) -> float { (*self as f64).jn(n) as float }
#[inline]
fn y0(&self) -> float { y0(*self as f64) as float }
fn y0(&self) -> float { (*self as f64).y0() as float }
#[inline]
fn y1(&self) -> float { y1(*self as f64) as float }
fn y1(&self) -> float { (*self as f64).y1() as float }
#[inline]
fn yn(&self, n: int) -> float { yn(n as c_int, *self as f64) as float }
fn yn(&self, n: int) -> float { (*self as f64).yn(n) as float }
}
#[cfg(not(test))]
@ -792,7 +756,7 @@ fn neg(&self) -> float { -*self }
impl Signed for float {
/// Computes the absolute value. Returns `NaN` if the number is `NaN`.
#[inline]
fn abs(&self) -> float { abs(*self) }
fn abs(&self) -> float { (*self as f64).abs() as float }
///
/// The positive difference of two numbers. Returns `0.0` if the number is less than or
@ -812,7 +776,7 @@ fn abs_sub(&self, other: &float) -> float {
///
#[inline]
fn signum(&self) -> float {
if self.is_NaN() { NaN } else { f64::copysign(1.0, *self as f64) as float }
(*self as f64).signum() as float
}
/// Returns `true` if the number is positive, including `+0.0` and `infinity`
@ -939,13 +903,13 @@ fn ln_1p(&self) -> float {
///
#[inline]
fn mul_add(&self, a: float, b: float) -> float {
mul_add(*self as f64, a as f64, b as f64) as float
(*self as f64).mul_add(a as f64, b as f64) as float
}
/// Returns the next representable floating-point value in the direction of `other`
#[inline]
fn next_after(&self, other: float) -> float {
next_after(*self as f64, other as f64) as float
(*self as f64).next_after(other as f64) as float
}
}

View file

@ -29,62 +29,6 @@ macro_rules! int_module (($T:ty, $bits:expr) => (mod generated {
pub static min_value: $T = (-1 as $T) << (bits - 1);
pub static max_value: $T = min_value - 1 as $T;
/// Calculates the sum of two numbers
#[inline]
pub fn add(x: $T, y: $T) -> $T { x + y }
/// Subtracts the second number from the first
#[inline]
pub fn sub(x: $T, y: $T) -> $T { x - y }
/// Multiplies two numbers together
#[inline]
pub fn mul(x: $T, y: $T) -> $T { x * y }
/// Divides the first argument by the second argument (using integer division)
/// Divides the first argument by the second argument (using integer division)
#[inline]
pub fn div(x: $T, y: $T) -> $T { x / y }
///
/// Returns the remainder of y / x.
///
/// # Examples
/// ~~~
/// assert!(int::rem(5 / 2) == 1);
/// ~~~
///
/// When faced with negative numbers, the result copies the sign of the
/// dividend.
///
/// ~~~
/// assert!(int::rem(2 / -3) == 2);
/// ~~~
///
/// ~~~
/// assert!(int::rem(-2 / 3) == -2);
/// ~~~
///
///
#[inline]
pub fn rem(x: $T, y: $T) -> $T { x % y }
/// Returns true iff `x < y`
#[inline]
pub fn lt(x: $T, y: $T) -> bool { x < y }
/// Returns true iff `x <= y`
#[inline]
pub fn le(x: $T, y: $T) -> bool { x <= y }
/// Returns true iff `x == y`
#[inline]
pub fn eq(x: $T, y: $T) -> bool { x == y }
/// Returns true iff `x != y`
#[inline]
pub fn ne(x: $T, y: $T) -> bool { x != y }
/// Returns true iff `x >= y`
#[inline]
pub fn ge(x: $T, y: $T) -> bool { x >= y }
/// Returns true iff `x > y`
#[inline]
pub fn gt(x: $T, y: $T) -> bool { x > y }
///
/// Iterate over the range [`lo`..`hi`)
///
@ -137,16 +81,6 @@ pub fn range_rev(hi: $T, lo: $T, it: &fn($T) -> bool) -> bool {
range_step(hi, lo, -1 as $T, it)
}
/// Computes the bitwise complement
#[inline]
pub fn compl(i: $T) -> $T {
-1 as $T ^ i
}
/// Computes the absolute value
#[inline]
pub fn abs(i: $T) -> $T { i.abs() }
impl Num for $T {}
#[cfg(not(test))]

View file

@ -46,6 +46,9 @@ pub trait Orderable: Ord {
fn clamp(&self, mn: &Self, mx: &Self) -> Self;
}
#[inline(always)] pub fn min<T: Orderable>(a: T, b: T) -> T { a.min(&b) }
#[inline(always)] pub fn max<T: Orderable>(a: T, b: T) -> T { a.max(&b) }
pub trait Zero {
fn zero() -> Self; // FIXME (#5527): This should be an associated constant
fn is_zero(&self) -> bool;
@ -65,12 +68,10 @@ pub trait Signed: Num
fn is_negative(&self) -> bool;
}
pub trait Unsigned: Num {}
#[inline(always)] pub fn abs<T: Signed>(value: T) -> T { value.abs() }
#[inline(always)] pub fn signum<T: Signed>(value: T) -> T { value.signum() }
// This should be moved into the default implementation for Signed::abs
pub fn abs<T:Ord + Zero + Neg<T>>(v: T) -> T {
if v < Zero::zero() { v.neg() } else { v }
}
pub trait Unsigned: Num {}
pub trait Integer: Num
+ Orderable
@ -113,6 +114,8 @@ pub trait Algebraic {
fn hypot(&self, other: &Self) -> Self;
}
#[inline(always)] pub fn sqrt<T: Algebraic>(value: T) -> T { value.sqrt() }
pub trait Trigonometric {
fn sin(&self) -> Self;
fn cos(&self) -> Self;
@ -124,6 +127,16 @@ pub trait Trigonometric {
fn sin_cos(&self) -> (Self, Self);
}
#[inline(always)] pub fn sin<T: Trigonometric>(value: T) -> T { value.sin() }
#[inline(always)] pub fn cos<T: Trigonometric>(value: T) -> T { value.cos() }
#[inline(always)] pub fn tan<T: Trigonometric>(value: T) -> T { value.tan() }
#[inline(always)] pub fn asin<T: Trigonometric>(value: T) -> T { value.asin() }
#[inline(always)] pub fn acos<T: Trigonometric>(value: T) -> T { value.acos() }
#[inline(always)] pub fn atan<T: Trigonometric>(value: T) -> T { value.atan() }
#[inline(always)] pub fn atan2<T: Trigonometric>(x: T, y: T) -> T { x.atan2(&y) }
pub trait Exponential {
fn exp(&self) -> Self;
fn exp2(&self) -> Self;
@ -133,6 +146,14 @@ pub trait Exponential {
fn log10(&self) -> Self;
}
#[inline(always)] pub fn exp<T: Exponential>(value: T) -> T { value.exp() }
#[inline(always)] pub fn exp2<T: Exponential>(value: T) -> T { value.exp2() }
#[inline(always)] pub fn ln<T: Exponential>(value: T) -> T { value.ln() }
#[inline(always)] pub fn log<T: Exponential>(value: T, base: T) -> T { value.log(&base) }
#[inline(always)] pub fn log2<T: Exponential>(value: T) -> T { value.log2() }
#[inline(always)] pub fn log10<T: Exponential>(value: T) -> T { value.log10() }
pub trait Hyperbolic: Exponential {
fn sinh(&self) -> Self;
fn cosh(&self) -> Self;
@ -142,6 +163,14 @@ pub trait Hyperbolic: Exponential {
fn atanh(&self) -> Self;
}
#[inline(always)] pub fn sinh<T: Hyperbolic>(value: T) -> T { value.sinh() }
#[inline(always)] pub fn cosh<T: Hyperbolic>(value: T) -> T { value.cosh() }
#[inline(always)] pub fn tanh<T: Hyperbolic>(value: T) -> T { value.tanh() }
#[inline(always)] pub fn asinh<T: Hyperbolic>(value: T) -> T { value.asinh() }
#[inline(always)] pub fn acosh<T: Hyperbolic>(value: T) -> T { value.acosh() }
#[inline(always)] pub fn atanh<T: Hyperbolic>(value: T) -> T { value.atanh() }
///
/// Defines constants and methods common to real numbers
///

View file

@ -30,42 +30,6 @@ macro_rules! uint_module (($T:ty, $T_SIGNED:ty, $bits:expr) => (mod generated {
pub static min_value: $T = 0 as $T;
pub static max_value: $T = 0 as $T - 1 as $T;
/// Calculates the sum of two numbers
#[inline]
pub fn add(x: $T, y: $T) -> $T { x + y }
/// Subtracts the second number from the first
#[inline]
pub fn sub(x: $T, y: $T) -> $T { x - y }
/// Multiplies two numbers together
#[inline]
pub fn mul(x: $T, y: $T) -> $T { x * y }
/// Divides the first argument by the second argument (using integer division)
#[inline]
pub fn div(x: $T, y: $T) -> $T { x / y }
/// Calculates the integer remainder when x is divided by y (equivalent to the
/// '%' operator)
#[inline]
pub fn rem(x: $T, y: $T) -> $T { x % y }
/// Returns true iff `x < y`
#[inline]
pub fn lt(x: $T, y: $T) -> bool { x < y }
/// Returns true iff `x <= y`
#[inline]
pub fn le(x: $T, y: $T) -> bool { x <= y }
/// Returns true iff `x == y`
#[inline]
pub fn eq(x: $T, y: $T) -> bool { x == y }
/// Returns true iff `x != y`
#[inline]
pub fn ne(x: $T, y: $T) -> bool { x != y }
/// Returns true iff `x >= y`
#[inline]
pub fn ge(x: $T, y: $T) -> bool { x >= y }
/// Returns true iff `x > y`
#[inline]
pub fn gt(x: $T, y: $T) -> bool { x > y }
#[inline]
/**
* Iterate through a range with a given step value.
@ -114,12 +78,6 @@ pub fn range_rev(hi: $T, lo: $T, it: &fn($T) -> bool) -> bool {
range_step(hi, lo, -1 as $T_SIGNED, it)
}
/// Computes the bitwise complement
#[inline]
pub fn compl(i: $T) -> $T {
max_value ^ i
}
impl Num for $T {}
#[cfg(not(test))]

View file

@ -46,6 +46,7 @@ fn main () {
use int;
use iterator::IteratorUtil;
use local_data;
use num;
use prelude::*;
use str;
use sys;
@ -463,7 +464,7 @@ fn gen<T: Rand>(&mut self) -> T {
*/
fn gen_int_range(&mut self, start: int, end: int) -> int {
assert!(start < end);
start + int::abs(self.gen::<int>() % (end - start))
start + num::abs(self.gen::<int>() % (end - start))
}
/**

View file

@ -20,7 +20,7 @@
// Generating Random Variables"], but more robust. If one wanted, one
// could implement VIZIGNOR the ZIGNOR paper for more speed.
use f64;
use num;
use rand::{Rng,Rand};
mod ziggurat_tables;
@ -39,7 +39,7 @@ fn ziggurat<R:Rng>(rng: &mut R,
let i: uint = rng.gen::<uint>() & 0xff;
let x = u * X[i];
let test_x = if center_u {f64::abs(x)} else {x};
let test_x = if center_u {num::abs(x)} else {x};
// algebraically equivalent to |u| < X[i+1]/X[i] (or u < X[i+1]/X[i])
if test_x < X[i + 1] {
@ -79,7 +79,7 @@ impl Rand for StandardNormal {
fn rand<R:Rng>(rng: &mut R) -> StandardNormal {
#[inline]
fn pdf(x: f64) -> f64 {
f64::exp((-x*x/2.0) as f64) as f64
((-x*x/2.0) as f64).exp()
}
#[inline]
fn zero_case<R:Rng>(rng: &mut R, u: f64) -> f64 {
@ -89,15 +89,16 @@ fn zero_case<R:Rng>(rng: &mut R, u: f64) -> f64 {
// do-while, so the condition should be true on the first
// run, they get overwritten anyway (0 < 1, so these are
// good).
let mut x = 1.0;
let mut y = 0.0;
let mut x = 1.0f64;
let mut y = 0.0f64;
// XXX infinities?
while -2.0*y < x * x {
x = f64::ln(rng.gen()) / ziggurat_tables::ZIG_NORM_R;
y = f64::ln(rng.gen());
while -2.0 * y < x * x {
x = rng.gen::<f64>().ln() / ziggurat_tables::ZIG_NORM_R;
y = rng.gen::<f64>().ln();
}
if u < 0.0 {x-ziggurat_tables::ZIG_NORM_R} else {ziggurat_tables::ZIG_NORM_R-x}
if u < 0.0 { x - ziggurat_tables::ZIG_NORM_R } else { ziggurat_tables::ZIG_NORM_R - x }
}
StandardNormal(ziggurat(
@ -128,17 +129,17 @@ fn zero_case<R:Rng>(rng: &mut R, u: f64) -> f64 {
/// ~~~
pub struct Exp1(f64);
// This could be done via `-f64::ln(rng.gen::<f64>())` but that is slower.
// This could be done via `-rng.gen::<f64>().ln()` but that is slower.
impl Rand for Exp1 {
#[inline]
fn rand<R:Rng>(rng: &mut R) -> Exp1 {
#[inline]
fn pdf(x: f64) -> f64 {
f64::exp(-x)
(-x).exp()
}
#[inline]
fn zero_case<R:Rng>(rng: &mut R, _u: f64) -> f64 {
ziggurat_tables::ZIG_EXP_R - f64::ln(rng.gen())
ziggurat_tables::ZIG_EXP_R - rng.gen::<f64>().ln()
}
Exp1(ziggurat(rng, false,

View file

@ -477,7 +477,7 @@ pub mod rt {
use float;
use str;
use sys;
use int;
use num;
use uint;
use vec;
use option::{Some, None, Option};
@ -503,7 +503,7 @@ pub struct Conv {
pub fn conv_int(cv: Conv, i: int, buf: &mut ~str) {
let radix = 10;
let prec = get_int_precision(cv);
let s : ~str = uint_to_str_prec(int::abs(i) as uint, radix, prec);
let s : ~str = uint_to_str_prec(num::abs(i) as uint, radix, prec);
let head = if i >= 0 {
if have_flag(cv.flags, flag_sign_always) {

View file

@ -1964,7 +1964,7 @@ pub unsafe fn copy_memory<T>(dst: &mut [T], src: &[T],
/// Operations on `[u8]`
pub mod bytes {
use libc;
use uint;
use num;
use vec::raw;
use vec;
use ptr;
@ -1988,7 +1988,7 @@ fn set_memory(self, value: u8) {
pub fn memcmp(a: &~[u8], b: &~[u8]) -> int {
let a_len = a.len();
let b_len = b.len();
let n = uint::min(a_len, b_len) as libc::size_t;
let n = num::min(a_len, b_len) as libc::size_t;
let r = unsafe {
libc::memcmp(raw::to_ptr(*a) as *libc::c_void,
raw::to_ptr(*b) as *libc::c_void, n) as int

View file

@ -18,6 +18,7 @@
use std::hashmap::HashMap;
use std::int;
use std::num;
use std::option;
use std::cast;
use std::local_data;
@ -376,8 +377,8 @@ pub fn empty(&self) -> bool {
}
pub fn add(&mut self, id: node_id) {
self.min = int::min(self.min, id);
self.max = int::max(self.max, id + 1);
self.min = num::min(self.min, id);
self.max = num::max(self.max, id + 1);
}
}

View file

@ -22,7 +22,7 @@
use extra::deque::Deque;
use extra::par;
use std::hashmap::HashSet;
use std::int::abs;
use std::num::abs;
use std::io;
use std::os;
use std::rand::RngUtil;

View file

@ -1,6 +1,5 @@
// Perlin noise benchmark from https://gist.github.com/1170424
use std::f32;
use std::float;
use std::int;
use std::rand::{Rng, RngUtil};
@ -20,8 +19,8 @@ fn smooth(v: f32) -> f32 { v * v * (3.0 - 2.0 * v) }
fn random_gradient<R:Rng>(r: &mut R) -> Vec2 {
let v = 2.0 * float::consts::pi * r.gen();
Vec2 {
x: float::cos(v) as f32,
y: float::sin(v) as f32,
x: v.cos() as f32,
y: v.sin() as f32,
}
}
@ -66,8 +65,8 @@ pub fn get_gradients(&self,
origins: &mut [Vec2, ..4],
x: f32,
y: f32) {
let x0f = f32::floor(x);
let y0f = f32::floor(y);
let x0f = x.floor();
let y0f = y.floor();
let x0 = x0f as int;
let y0 = y0f as int;
let x1 = x0 + 1;

View file

@ -1,4 +1,3 @@
use std::f64;
use std::from_str::FromStr;
use std::os;
use std::uint::range;
@ -90,7 +89,7 @@ fn advance(bodies: &mut [Planet, ..N_BODIES], dt: f64, steps: i32) {
d[2] = bodies[i].x[2] - bodies[j].x[2];
let d2 = d[0]*d[0] + d[1]*d[1] + d[2]*d[2];
let mag = dt / (d2 * f64::sqrt(d2));
let mag = dt / (d2 * d2.sqrt());
let a_mass = bodies[i].mass;
let b_mass = bodies[j].mass;
@ -124,7 +123,7 @@ fn energy(bodies: &[Planet, ..N_BODIES]) -> f64 {
for range(0, 3) |k| {
d[k] = bodies[i].x[k] - bodies[j].x[k];
}
let dist = f64::sqrt(d[0]*d[0] + d[1]*d[1] + d[2]*d[2]);
let dist = (d[0]*d[0] + d[1]*d[1] + d[2]*d[2]).sqrt();
e -= bodies[i].mass * bodies[j].mass / dist;
}
}

View file

@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::f64;
use std::from_str::FromStr;
use std::os;
use std::vec;
@ -62,5 +61,5 @@ fn main() {
mult_AtAv(v, u, tmp);
}
println(fmt!("%.9f", f64::sqrt(dot(u,v) / dot(v,v)) as float));
println(fmt!("%.9f", (dot(u,v) / dot(v,v)).sqrt() as float));
}

View file

@ -58,7 +58,7 @@ fn [](&&k:int) -> bool { k <= self.meows }
fn find(&&k:int) -> Option<bool> { Some(self.get(k)) }
fn remove(&&k:int) -> Option<bool> { self.meows -= k; Some(true) }
fn each(f: &fn(&&int, &&bool) -> bool) {
let mut n = int::abs(self.meows);
let mut n = num::abs(self.meows);
while n > 0 {
if !f(n, true) { break; }
n -= 1;

View file

@ -1,21 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Regression test that f64 exports things properly
use std::f64;
use std::float;
pub fn main() {
let digits: uint = 10 as uint;
println(float::to_str_digits(f64::sqrt(42.0f64) as float, digits));
}

View file

@ -1,7 +1,6 @@
// Test for issue #4183: use of Self in supertraits.
use std::f32;
use std::f64;
use std::num;
pub static FUZZY_EPSILON: float = 0.1;
@ -20,7 +19,7 @@ fn fuzzy_eq(&self, other: &f32) -> bool {
}
fn fuzzy_eq_eps(&self, other: &f32, epsilon: &f32) -> bool {
f32::abs(*self - *other) < *epsilon
num::abs(*self - *other) < *epsilon
}
}
@ -34,7 +33,7 @@ fn fuzzy_eq(&self, other: &f64) -> bool {
}
fn fuzzy_eq_eps(&self, other: &f64, epsilon: &f64) -> bool {
f64::abs(*self - *other) < *epsilon
num::abs(*self - *other) < *epsilon
}
}

View file

@ -8,13 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::float;
use std::num;
pub fn main() {
let ε = 0.00001;
let Π = 3.14;
let = Π * Π + 1.54;
assert!(float::abs(( - 1.54) - (Π * Π)) < ε);
assert!(num::abs(( - 1.54) - (Π * Π)) < ε);
assert_eq!(_გემრიელი_სადილი(), 0);
}