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:
commit
e388a80c23
41 changed files with 178 additions and 376 deletions
|
|
@ -22,7 +22,7 @@ use extra::time;
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -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 @@ impl Noise2DContext {
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class cat : map<int, bool> {
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
|
@ -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 @@ impl FuzzyEq<f32> for f32 {
|
|||
}
|
||||
|
||||
fn fuzzy_eq_eps(&self, other: &f32, epsilon: &f32) -> bool {
|
||||
f32::abs(*self - *other) < *epsilon
|
||||
num::abs(*self - *other) < *epsilon
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -34,7 +33,7 @@ impl FuzzyEq<f64> for f64 {
|
|||
}
|
||||
|
||||
fn fuzzy_eq_eps(&self, other: &f64, epsilon: &f64) -> bool {
|
||||
f64::abs(*self - *other) < *epsilon
|
||||
num::abs(*self - *other) < *epsilon
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue