auto merge of #9519 : thestinger/rust/float, r=catamorphism

It is simply defined as `f64` across every platform right now.

A use case hasn't been presented for a `float` type defined as the
highest precision floating point type implemented in hardware on the
platform. Performance-wise, using the smallest precision correct for the
use case greatly saves on cache space and allows for fitting more
numbers into SSE/AVX registers.

If there was a use case, this could be implemented as simply a type
alias or a struct thanks to `#[cfg(...)]`.

Closes #6592

The mailing list thread, for reference:

https://mail.mozilla.org/pipermail/rust-dev/2013-July/004632.html
This commit is contained in:
bors 2013-10-01 13:01:28 -07:00
commit 08b510c351
136 changed files with 606 additions and 2209 deletions

View file

@ -15,9 +15,9 @@ pub mod num {
}
}
pub mod float {
impl ::num::Num2 for float {
pub mod f64 {
impl ::num::Num2 for f64 {
#[inline]
fn from_int2(n: int) -> float { return n as float; }
fn from_int2(n: int) -> f64 { return n as f64; }
}
}

View file

@ -4,8 +4,8 @@ pub mod num {
}
}
pub mod float {
impl ::num::Num2 for float {
fn from_int2(n: int) -> float { return n as float; }
pub mod f64 {
impl ::num::Num2 for f64 {
fn from_int2(n: int) -> f64 { return n as f64; }
}
}

View file

@ -23,7 +23,7 @@ trait B<T> {
}
impl<T> B<T> for int { }
impl B<float> for bool { }
impl B<f64> for bool { }

View file

@ -16,7 +16,7 @@ pub enum Color {
}
condition! {
pub oops: (int,float,~str) -> Color;
pub oops: (int,f64,~str) -> Color;
}
pub trait Thunk<T> {

View file

@ -19,16 +19,16 @@ use std::rand;
use std::uint;
struct Results {
sequential_ints: float,
random_ints: float,
delete_ints: float,
sequential_ints: f64,
random_ints: f64,
delete_ints: f64,
sequential_strings: float,
random_strings: float,
delete_strings: float
sequential_strings: f64,
random_strings: f64,
delete_strings: f64
}
fn timed(result: &mut float, op: &fn()) {
fn timed(result: &mut f64, op: &fn()) {
let start = extra::time::precise_time_s();
op();
let end = extra::time::precise_time_s();
@ -127,7 +127,7 @@ fn write_header(header: &str) {
io::stdout().write_str("\n");
}
fn write_row(label: &str, value: float) {
fn write_row(label: &str, value: f64) {
io::stdout().write_str(format!("{:30s} {} s\n", label, value));
}
@ -143,13 +143,13 @@ fn write_results(label: &str, results: &Results) {
fn empty_results() -> Results {
Results {
sequential_ints: 0f,
random_ints: 0f,
delete_ints: 0f,
sequential_ints: 0.0,
random_ints: 0.0,
delete_ints: 0.0,
sequential_strings: 0f,
random_strings: 0f,
delete_strings: 0f,
sequential_strings: 0.0,
random_strings: 0.0,
delete_strings: 0.0,
}
}

View file

@ -55,7 +55,7 @@ fn maybe_run_test(argv: &[~str], name: ~str, test: &fn()) {
test();
let stop = precise_time_s();
println!("{}:\t\t{} ms", name, (stop - start) * 1000f);
println!("{}:\t\t{} ms", name, (stop - start) * 1000.0);
}
fn shift_push() {

View file

@ -92,7 +92,7 @@ fn run(args: &[~str]) {
let elapsed = end - start;
io::stdout().write_str(format!("Count is {:?}\n", result));
io::stdout().write_str(format!("Test took {:?} seconds\n", elapsed));
let thruput = ((size / workers * workers) as float) / (elapsed as float);
let thruput = ((size / workers * workers) as f64) / (elapsed as f64);
io::stdout().write_str(format!("Throughput={} per sec\n", thruput));
assert_eq!(result, num_bytes * size);
}

View file

@ -86,7 +86,7 @@ fn run(args: &[~str]) {
let elapsed = end - start;
io::stdout().write_str(format!("Count is {:?}\n", result));
io::stdout().write_str(format!("Test took {:?} seconds\n", elapsed));
let thruput = ((size / workers * workers) as float) / (elapsed as float);
let thruput = ((size / workers * workers) as f64) / (elapsed as f64);
io::stdout().write_str(format!("Throughput={} per sec\n", thruput));
assert_eq!(result, num_bytes * size);
}

View file

@ -116,7 +116,7 @@ fn main() {
// all done, report stats.
let num_msgs = num_tasks * msg_per_task;
let elapsed = (stop - start);
let rate = (num_msgs as float) / elapsed;
let rate = (num_msgs as f64) / elapsed;
println!("Sent {} messages in {} seconds", num_msgs, elapsed);
println!(" {} messages / second", rate);

View file

@ -112,7 +112,7 @@ fn main() {
// all done, report stats.
let num_msgs = num_tasks * msg_per_task;
let elapsed = (stop - start);
let rate = (num_msgs as float) / elapsed;
let rate = (num_msgs as f64) / elapsed;
println!("Sent {} messages in {} seconds", num_msgs, elapsed);
println!(" {} messages / second", rate);

View file

@ -1,6 +1,6 @@
// Perlin noise benchmark from https://gist.github.com/1170424
use std::float;
use std::f64;
use std::rand::Rng;
use std::rand;
@ -16,7 +16,7 @@ fn lerp(a: f32, b: f32, v: f32) -> f32 { a * (1.0 - v) + b * v }
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();
let v = 2.0 * f64::consts::pi * r.gen();
Vec2 {
x: v.cos() as f32,
y: v.sin() as f32,

View file

@ -29,8 +29,8 @@ use std::vec;
// given a map, print a sorted version of it
fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str {
fn pct(xx: uint, yy: uint) -> float {
return (xx as float) * 100f / (yy as float);
fn pct(xx: uint, yy: uint) -> f64 {
return (xx as f64) * 100.0 / (yy as f64);
}
fn le_by_val<TT:Clone,

View file

@ -53,11 +53,11 @@ fn main() {
check_sequential(0u, max, &map);
let end = extra::time::precise_time_s();
checkf += (end - mid) as float;
appendf += (mid - start) as float;
checkf += (end - mid) as f64;
appendf += (mid - start) as f64;
}
let maxf = max as float;
let maxf = max as f64;
io::stdout().write_str(format!("insert(): {:?} seconds\n", checkf));
io::stdout().write_str(format!(" : {} op/sec\n", maxf/checkf));

View file

@ -29,9 +29,9 @@ impl Trait<int> for S2 {
}
fn main() {
let _ = S::new::<int,float>(1, 1.0); //~ ERROR the impl referenced by this path has 1 type parameter, but 0 type parameters were supplied
let _ = S::<'self,int>::new::<float>(1, 1.0); //~ ERROR this impl has no lifetime parameter
let _: S2 = Trait::new::<int,float>(1, 1.0); //~ ERROR the trait referenced by this path has 1 type parameter, but 0 type parameters were supplied
let _: S2 = Trait::<'self,int>::new::<float>(1, 1.0); //~ ERROR this trait has no lifetime parameter
let _ = S::new::<int,f64>(1, 1.0); //~ ERROR the impl referenced by this path has 1 type parameter, but 0 type parameters were supplied
let _ = S::<'self,int>::new::<f64>(1, 1.0); //~ ERROR this impl has no lifetime parameter
let _: S2 = Trait::new::<int,f64>(1, 1.0); //~ ERROR the trait referenced by this path has 1 type parameter, but 0 type parameters were supplied
let _: S2 = Trait::<'self,int>::new::<f64>(1, 1.0); //~ ERROR this trait has no lifetime parameter
}

View file

@ -8,15 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn compute1() -> float {
let v = ~[0f, 1f, 2f, 3f];
fn compute1() -> f64 {
let v = ~[0f64, 1.0, 2.0, 3.0];
do v.iter().fold(0f) |x, y| { x + *y } - 10f
do v.iter().fold(0.0) |x, y| { x + *y } - 10.0
//~^ ERROR mismatched types: expected `()`
}
fn main() {
let x = compute1();
info2!("{:?}", x);
assert_eq!(x, -4f);
assert_eq!(x, -4f64);
}

View file

@ -10,7 +10,7 @@
use std::either::{Either, Left, Right};
fn f(x: &mut Either<int,float>, y: &Either<int,float>) -> int {
fn f(x: &mut Either<int,f64>, y: &Either<int,f64>) -> int {
match *y {
Left(ref z) => {
*x = Right(1.0);
@ -21,14 +21,14 @@ use std::either::{Either, Left, Right};
}
fn g() {
let mut x: Either<int,float> = Left(3);
let mut x: Either<int,f64> = Left(3);
println(f(&mut x, &x).to_str()); //~ ERROR cannot borrow
}
fn h() {
let mut x: Either<int,float> = Left(3);
let y: &Either<int, float> = &x;
let z: &mut Either<int, float> = &mut x; //~ ERROR cannot borrow
let mut x: Either<int,f64> = Left(3);
let y: &Either<int, f64> = &x;
let z: &mut Either<int, f64> = &mut x; //~ ERROR cannot borrow
*z = *y;
}

View file

@ -10,5 +10,5 @@
fn main() {
let x: f32 = 1; //~ ERROR mismatched types
let y: f32 = 1f; //~ ERROR mismatched types
let y: f32 = 1f64; //~ ERROR mismatched types
}

View file

@ -12,12 +12,12 @@
use std::io;
struct Point {
x: float,
y: float,
x: f64,
y: f64,
}
impl ToStr for Point { //~ ERROR implements a method not defined in the trait
fn new(x: float, y: float) -> Point {
fn new(x: f64, y: f64) -> Point {
Point { x: x, y: y }
}

View file

@ -1,6 +1,6 @@
// Matching against NaN should result in a warning
use std::float::NaN;
use std::f64::NaN;
fn main() {
let x = NaN;

View file

@ -19,7 +19,7 @@ mod issue6633 {
pub mod name {
pub type a = int;
pub mod name {
pub type a = float;
pub type a = f64;
}
}
}

View file

@ -13,7 +13,7 @@ use std::local_data;
// check that the local data keys are private by default.
mod bar {
local_data_key!(baz: float)
local_data_key!(baz: f64)
}
fn main() {

View file

@ -11,7 +11,7 @@
// error-pattern:binary float literal is not supported
fn main() {
0b101010f;
0b101010f64;
0b101.010;
0b101p4f;
0b101p4f64;
}

View file

@ -20,7 +20,6 @@ let x: u8<int>; //~ ERROR type parameters are not allowed on this type
let x: u16<int>; //~ ERROR type parameters are not allowed on this type
let x: u32<int>; //~ ERROR type parameters are not allowed on this type
let x: u64<int>; //~ ERROR type parameters are not allowed on this type
let x: float<int>; //~ ERROR type parameters are not allowed on this type
let x: char<int>; //~ ERROR type parameters are not allowed on this type
let x: int<'static>; //~ ERROR lifetime parameters are not allowed on this type
@ -33,7 +32,6 @@ let x: u8<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: u16<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: u32<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: u64<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: float<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: char<'static>; //~ ERROR lifetime parameters are not allowed on this type
}

View file

@ -9,5 +9,5 @@
// except according to those terms.
fn main() {
let vec = bytes!(45f); //~ ERROR Unsupported literal in bytes!
let vec = bytes!(45f64); //~ ERROR Unsupported literal in bytes!
}

View file

@ -10,7 +10,7 @@
// Issue #6155
fn first((value, _): (int, float)) -> int { value }
fn first((value, _): (int, f64)) -> int { value }
fn main() {
let y = first ((1,2,3)); //~ ERROR expected a tuple with 2 elements but found one with 3 elements

View file

@ -42,12 +42,10 @@
// check:$11 = 32
// debugger:print u64
// check:$12 = 64
// debugger:print f
// check:$13 = 1.5
// debugger:print f32
// check:$14 = 2.5
// check:$13 = 2.5
// debugger:print f64
// check:$15 = 3.5
// check:$14 = 3.5
#[allow(unused_variable)];
@ -64,7 +62,6 @@ fn main() {
let u16: u16 = 16;
let u32: u32 = 32;
let u64: u64 = 64;
let f: float = 1.5;
let f32: f32 = 2.5;
let f64: f64 = 3.5;
_zzz();

View file

@ -51,14 +51,11 @@
// debugger:print *u64_ref
// check:$12 = 64
// debugger:print *float_ref
// check:$13 = 1.5
// debugger:print *f32_ref
// check:$14 = 2.5
// check:$13 = 2.5
// debugger:print *f64_ref
// check:$15 = 3.5
// check:$14 = 3.5
#[allow(unused_variable)];
@ -99,9 +96,6 @@ fn main() {
let u64_val: u64 = 64;
let u64_ref: &u64 = &u64_val;
let float_val: float = 1.5;
let float_ref: &float = &float_val;
let f32_val: f32 = 2.5;
let f32_ref: &f32 = &f32_val;

View file

@ -51,14 +51,11 @@
// debugger:print *u64_ref
// check:$12 = 64
// debugger:print *float_ref
// check:$13 = 1.5
// debugger:print *f32_ref
// check:$14 = 2.5
// check:$13 = 2.5
// debugger:print *f64_ref
// check:$15 = 3.5
// check:$14 = 3.5
#[allow(unused_variable)];
@ -99,9 +96,6 @@ fn main() {
let u64_box: @u64 = @64;
let u64_ref: &u64 = u64_box;
let float_box: @float = @1.5;
let float_ref: &float = float_box;
let f32_box: @f32 = @2.5;
let f32_ref: &f32 = f32_box;

View file

@ -51,14 +51,11 @@
// debugger:print *u64_ref
// check:$12 = 64
// debugger:print *float_ref
// check:$13 = 1.5
// debugger:print *f32_ref
// check:$14 = 2.5
// check:$13 = 2.5
// debugger:print *f64_ref
// check:$15 = 3.5
// check:$14 = 3.5
#[allow(unused_variable)];
@ -100,9 +97,6 @@ fn main() {
let u64_box: ~u64 = ~64;
let u64_ref: &u64 = u64_box;
let float_box: ~float = ~1.5;
let float_ref: &float = float_box;
let f32_box: ~f32 = ~2.5;
let f32_ref: &f32 = f32_box;

View file

@ -44,7 +44,7 @@
#[deriving(Clone)]
struct Struct {
a: int,
b: float
b: f64
}
#[deriving(Clone)]
@ -61,11 +61,11 @@ fn fun_fun(StructStruct { a: x, b: Struct { a: y, b: z } }: StructStruct) {
zzz();
}
fn tup(a: (int, uint, float, float)) {
fn tup(a: (int, uint, f64, f64)) {
zzz();
}
struct Newtype(float, float, int, uint);
struct Newtype(f64, f64, int, uint);
fn new_type(a: Newtype) {
zzz();

View file

@ -55,8 +55,8 @@ impl Trait for Struct {
}
}
impl Trait for (float, int, int, float) {
fn method(self) -> (float, int, int, float) {
impl Trait for (f64, int, int, f64) {
fn method(self) -> (f64, int, int, f64) {
zzz();
self
}

View file

@ -190,7 +190,7 @@ enum Univariant {
Unit(i32)
}
struct TupleStruct (float, int);
struct TupleStruct (f64, int);
fn simple_tuple((a, b): (int, bool)) {

View file

@ -134,7 +134,7 @@ enum Univariant {
Unit(i32)
}
struct TupleStruct (float, int);
struct TupleStruct (f64, int);
fn main() {

View file

@ -42,7 +42,7 @@
#[deriving(Clone)]
struct Struct {
a: int,
b: float
b: f64
}
fn dup_tup<T0: Clone, T1: Clone>(t0: &T0, t1: &T1) -> ((T0, T1), (T1, T0)) {

View file

@ -46,7 +46,7 @@ impl Struct {
enum Enum {
Variant1 { x: int },
Variant2,
Variant3(float, int, char),
Variant3(f64, int, char),
}
impl Enum {

View file

@ -92,7 +92,7 @@
// check:$21 = -16
// debugger:continue
struct TupleStruct(int, float);
struct TupleStruct(int, f64);
impl TupleStruct {

View file

@ -46,12 +46,12 @@ impl Struct {
enum Enum {
Variant1 { x: int },
Variant2,
Variant3(float, int, char),
Variant3(f64, int, char),
}
impl Enum {
fn static_method(arg1: int, arg2: float, arg3: uint) -> int {
fn static_method(arg1: int, arg2: f64, arg3: uint) -> int {
zzz();
arg1
}

View file

@ -19,7 +19,7 @@ trait Trait {
struct Struct {
a: int,
b: float
b: f64
}
impl Trait for Struct {}

View file

@ -50,7 +50,7 @@
struct Struct {
a: int,
b: float,
b: f64,
c: uint
}

View file

@ -24,7 +24,7 @@
struct Struct {
a: int,
b: float,
b: f64,
c: uint
}

View file

@ -30,7 +30,7 @@
struct Struct {
a: int,
b: float,
b: f64,
c: uint
}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:left: 1.0000001 does not approximately equal right: 1 with epsilon: 0.0000001
// error-pattern:left: 1.0000001f64 does not approximately equal right: 1f64 with epsilon: 0.0000001f64
pub fn main() {
assert_approx_eq!(1.0000001f, 1.0f, 1.0e-7);
assert_approx_eq!(1.0000001f64, 1.0f64, 1.0e-7);
}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:left: 1.00001 does not approximately equal right: 1
// error-pattern:left: 1.00001f64 does not approximately equal right: 1f64
pub fn main() {
assert_approx_eq!(1.00001f, 1.0f);
assert_approx_eq!(1.00001f64, 1.0);
}

View file

@ -9,8 +9,8 @@
// except according to those terms.
pub fn main() {
assert_approx_eq!(1.0f, 1.0f);
assert_approx_eq!(1.0000001f, 1.0f);
assert_approx_eq!(1.0000001f, 1.0f, 1.0e-6);
assert_approx_eq!(1.000001f, 1.0f, 1.0e-5);
assert_approx_eq!(1.0f64, 1.0);
assert_approx_eq!(1.0000001f64, 1.0);
assert_approx_eq!(1.0000001f64, 1.0, 1.0e-6);
assert_approx_eq!(1.000001f64, 1.0, 1.0e-5);
}

View file

@ -9,10 +9,10 @@
// except according to those terms.
pub fn main() {
let v = ~[-1f, 0f, 1f, 2f, 3f];
let v = ~[-1.0, 0.0, 1.0, 2.0, 3.0];
// Trailing expressions don't require parentheses:
let y = do v.iter().fold(0f) |x, y| { x + *y } + 10f;
let y = do v.iter().fold(0.0) |x, y| { x + *y } + 10.0;
assert_eq!(y, 15f);
assert_eq!(y, 15.0);
}

View file

@ -10,7 +10,7 @@
pub fn main() {
fn f(i: &fn() -> uint) -> uint { i() }
let v = ~[-1f, 0f, 1f, 2f, 3f];
let v = ~[-1.0, 0.0, 1.0, 2.0, 3.0];
let z = do do v.iter().fold(f) |x, _y| { x } { 22u };
assert_eq!(z, 22u);
}

View file

@ -10,7 +10,7 @@
pub fn main() {
fn f(i: uint) -> uint { i }
let v = ~[-1f, 0f, 1f, 2f, 3f];
let v = ~[-1.0, 0.0, 1.0, 2.0, 3.0];
let z = do v.iter().fold(f) |x, _y| { x } (22u);
assert_eq!(z, 22u);
}

View file

@ -10,7 +10,7 @@
// Check usage and precedence of block arguments in expressions:
pub fn main() {
let v = ~[-1f, 0f, 1f, 2f, 3f];
let v = ~[-1.0f64, 0.0, 1.0, 2.0, 3.0];
// Statement form does not require parentheses:
for i in v.iter() {
@ -26,7 +26,7 @@ pub fn main() {
assert!(any_negative);
// Higher precedence than unary operations:
let abs_v = do v.iter().map |e| { e.abs() }.collect::<~[float]>();
let abs_v = do v.iter().map |e| { e.abs() }.collect::<~[f64]>();
assert!(do abs_v.iter().all |e| { e.is_positive() });
assert!(!do abs_v.iter().any |e| { e.is_negative() });
@ -48,9 +48,9 @@ pub fn main() {
// Lower precedence than binary operations:
let w = do v.iter().fold(0f) |x, y| { x + *y } + 10f;
let y = do v.iter().fold(0f) |x, y| { x + *y } + 10f;
let z = 10f + do v.iter().fold(0f) |x, y| { x + *y };
let w = do v.iter().fold(0.0) |x, y| { x + *y } + 10.0;
let y = do v.iter().fold(0.0) |x, y| { x + *y } + 10.0;
let z = 10.0 + do v.iter().fold(0.0) |x, y| { x + *y };
assert_eq!(w, y);
assert_eq!(y, z);

View file

@ -1,18 +1,18 @@
static a: int = -4 + 3;
static a2: uint = 3 + 3;
static b: float = 3.0 + 2.7;
static b: f64 = 3.0 + 2.7;
static c: int = 3 - 4;
static d: uint = 3 - 3;
static e: float = 3.0 - 2.7;
static e: f64 = 3.0 - 2.7;
static e2: int = -3 * 3;
static f: uint = 3 * 3;
static g: float = 3.3 * 3.3;
static g: f64 = 3.3 * 3.3;
static h: int = 3 / -1;
static i: uint = 3 / 3;
static j: float = 3.3 / 3.3;
static j: f64 = 3.3 / 3.3;
static n: bool = true && false;

View file

@ -12,7 +12,7 @@
static lsl : int = 1 << 2;
static add : int = 1 + 2;
static addf : float = 1.0f + 2.0f;
static addf : f64 = 1.0 + 2.0;
static not : int = !0;
static notb : bool = !true;
static neg : int = -(1);
@ -20,7 +20,7 @@ static neg : int = -(1);
pub fn main() {
assert_eq!(lsl, 4);
assert_eq!(add, 3);
assert_eq!(addf, 3.0f);
assert_eq!(addf, 3.0);
assert_eq!(not, -1);
assert_eq!(notb, false);
assert_eq!(neg, -1);

View file

@ -14,12 +14,12 @@ enum B { B1=0, B2=2 }
pub fn main () {
static c1: int = A2 as int;
static c2: int = B2 as int;
static c3: float = A2 as float;
static c4: float = B2 as float;
static c3: f64 = A2 as f64;
static c4: f64 = B2 as f64;
let a1 = A2 as int;
let a2 = B2 as int;
let a3 = A2 as float;
let a4 = B2 as float;
let a3 = A2 as f64;
let a4 = B2 as f64;
assert_eq!(c1, 1);
assert_eq!(c2, 2);
assert_eq!(c3, 1.0);

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Pair { a: float, b: float }
struct Pair { a: f64, b: f64 }
struct AnotherPair { x: (i64, i64), y: Pair }

View file

@ -22,7 +22,6 @@ struct S {
_u32: u32,
_u64: u64,
_float: float,
_f32: f32,
_f64: f64,

View file

@ -11,7 +11,7 @@
#[deriving(Eq)]
enum Foo {
Bar(int, int),
Baz(float, float)
Baz(f64, f64)
}
pub fn main() {

View file

@ -26,7 +26,7 @@ struct E { a: int, b: int }
struct Lots {
d: u8,
e: char,
f: float,
f: f64,
g: (f32, char),
h: @mut (int, int),
i: bool,

View file

@ -19,5 +19,5 @@ fn foo_func<A, B: thing<A>>(x: B) -> Option<A> { x.foo() }
struct A { a: int }
pub fn main() {
let _x: Option<float> = foo_func(0);
let _x: Option<f64> = foo_func(0);
}

View file

@ -21,5 +21,5 @@ pub fn main() {
fn test_color(color: color, val: int, _name: ~str) {
assert!(color as int == val);
assert!(color as float == val as float);
assert!(color as f64 == val as f64);
}

View file

@ -2,8 +2,8 @@
#[allow(unused_variable)];
enum Animal {
Dog (~str, float),
Cat { name: ~str, weight: float }
Dog (~str, f64),
Cat { name: ~str, weight: f64 }
}
pub fn main() {

View file

@ -9,17 +9,17 @@
// except according to those terms.
static tau: float = 2.0*3.14159265358979323;
static tau: f64 = 2.0*3.14159265358979323;
struct Point {x: float, y: float}
struct Size {w: float, h: float}
struct Point {x: f64, y: f64}
struct Size {w: f64, h: f64}
enum shape {
circle(Point, float),
circle(Point, f64),
rectangle(Point, Size)
}
fn compute_area(shape: &shape) -> float {
fn compute_area(shape: &shape) -> f64 {
match *shape {
circle(_, radius) => 0.5 * tau * radius * radius,
rectangle(_, ref size) => size.w * size.h
@ -28,14 +28,14 @@ fn compute_area(shape: &shape) -> float {
impl shape {
// self is in the implicit self region
pub fn select<'r, T>(&self, threshold: float, a: &'r T, b: &'r T)
pub fn select<'r, T>(&self, threshold: f64, a: &'r T, b: &'r T)
-> &'r T {
if compute_area(self) > threshold {a} else {b}
}
}
fn select_based_on_unit_circle<'r, T>(
threshold: float, a: &'r T, b: &'r T) -> &'r T {
threshold: f64, a: &'r T, b: &'r T) -> &'r T {
let shape = &circle(Point{x: 0.0, y: 0.0}, 1.0);
shape.select(threshold, a, b)

View file

@ -15,7 +15,7 @@ struct S {
pub fn main() {
let x: f32 = 4.0;
println(x.to_str());
let y: float = 64.0;
let y: f64 = 64.0;
println(y.to_str());
let z = S { z: 1.0 };
println(z.z.to_str());

View file

@ -13,11 +13,11 @@ extern mod extra;
use std::num::Float;
pub fn main() {
let nan: float = Float::nan();
let nan: f64 = Float::nan();
assert!((nan).is_nan());
let inf: float = Float::infinity();
let neg_inf: float = Float::neg_infinity();
let inf: f64 = Float::infinity();
let neg_inf: f64 = Float::neg_infinity();
assert_eq!(-inf, neg_inf);
assert!( nan != nan);
@ -80,14 +80,14 @@ pub fn main() {
assert!((nan * 1.).is_nan());
assert!((nan / 1.).is_nan());
assert!((nan / 0.).is_nan());
assert!((0f/0f).is_nan());
assert!((0.0/0.0f64).is_nan());
assert!((-inf + inf).is_nan());
assert!((inf - inf).is_nan());
assert!(!(-1f).is_nan());
assert!(!(0f).is_nan());
assert!(!(0.1f).is_nan());
assert!(!(1f).is_nan());
assert!(!(-1.0f64).is_nan());
assert!(!(0.0f64).is_nan());
assert!(!(0.1f64).is_nan());
assert!(!(1.0f64).is_nan());
assert!(!(inf).is_nan());
assert!(!(-inf).is_nan());
assert!(!(1./-inf).is_nan());

View file

@ -11,8 +11,8 @@
pub fn main() {
fn foo(n: float) -> float { return n + 0.12345; }
let n: float = 0.1;
let m: float = foo(n);
fn foo(n: f64) -> f64 { return n + 0.12345; }
let n: f64 = 0.1;
let m: f64 = foo(n);
info2!("{}", m);
}

View file

@ -56,7 +56,6 @@ pub fn main() {
t!(format!("{}", 1u16), "1");
t!(format!("{}", 1u32), "1");
t!(format!("{}", 1u64), "1");
t!(format!("{}", 1.0f), "1");
t!(format!("{}", 1.0f32), "1");
t!(format!("{}", 1.0f64), "1");
t!(format!("{}", "a"), "a");
@ -212,13 +211,12 @@ pub fn main() {
t!(format!("{:+05d}", -1), "-0001");
// Some float stuff
t!(format!("{:f}", 1.0f), "1");
t!(format!("{:f}", 1.0f32), "1");
t!(format!("{:f}", 1.0f64), "1");
t!(format!("{:.3f}", 1.0f), "1.000");
t!(format!("{:10.3f}", 1.0f), " 1.000");
t!(format!("{:+10.3f}", 1.0f), " +1.000");
t!(format!("{:+10.3f}", -1.0f), " -1.000");
t!(format!("{:.3f}", 1.0f64), "1.000");
t!(format!("{:10.3f}", 1.0f64), " 1.000");
t!(format!("{:+10.3f}", 1.0f64), " +1.000");
t!(format!("{:+10.3f}", -1.0f64), " -1.000");
// Escaping
t!(format!("\\{"), "{");

View file

@ -3,7 +3,7 @@ extern mod extra;
use std::comm::Chan;
use std::task;
type RingBuffer = ~[float];
type RingBuffer = ~[f64];
type SamplesFn = ~fn(samples: &RingBuffer);
enum Msg

View file

@ -9,14 +9,14 @@
// except according to those terms.
struct Vec2 {
x: float,
y: float
x: f64,
y: f64
}
// methods we want to export as methods as well as operators
impl Vec2 {
#[inline(always)]
fn vmul(self, other: float) -> Vec2 {
fn vmul(self, other: f64) -> Vec2 {
Vec2 { x: self.x * other, y: self.y * other }
}
}
@ -29,22 +29,22 @@ impl<Res, Rhs: RhsOfVec2Mul<Res>> Mul<Rhs,Res> for Vec2 {
fn mul(&self, rhs: &Rhs) -> Res { rhs.mul_vec2_by(self) }
}
// Implementation of 'float as right-hand-side of Vec2::Mul'
impl RhsOfVec2Mul<Vec2> for float {
// Implementation of 'f64 as right-hand-side of Vec2::Mul'
impl RhsOfVec2Mul<Vec2> for f64 {
fn mul_vec2_by(&self, lhs: &Vec2) -> Vec2 { lhs.vmul(*self) }
}
// Usage with failing inference
pub fn main() {
let a = Vec2 { x: 3f, y: 4f };
let a = Vec2 { x: 3.0, y: 4.0 };
// the following compiles and works properly
let v1: Vec2 = a * 3f;
let v1: Vec2 = a * 3.0;
println!("{} {}", v1.x, v1.y);
// the following compiles but v2 will not be Vec2 yet and
// using it later will cause an error that the type of v2
// must be known
let v2 = a * 3f;
let v2 = a * 3.0;
println!("{} {}", v2.x, v2.y); // error regarding v2's type
}

View file

@ -12,28 +12,28 @@
// Issue Name: pub method preceeded by attribute can't be parsed
// Abstract: Visibility parsing failed when compiler parsing
use std::float;
use std::f64;
struct Point {
x: float,
y: float
x: f64,
y: f64
}
pub enum Shape {
Circle(Point, float),
Circle(Point, f64),
Rectangle(Point, Point)
}
impl Shape {
pub fn area(&self, sh: Shape) -> float {
pub fn area(&self, sh: Shape) -> f64 {
match sh {
Circle(_, size) => float::consts::pi * size * size,
Circle(_, size) => f64::consts::pi * size * size,
Rectangle(Point {x, y}, Point {x: x2, y: y2}) => (x2 - x) * (y2 - y)
}
}
}
pub fn main(){
let s = Circle(Point { x: 1f, y: 2f }, 3f);
let s = Circle(Point { x: 1.0, y: 2.0 }, 3.0);
println!("{}", s.area(s));
}

View file

@ -9,7 +9,7 @@
// except according to those terms.
pub fn main() {
let _id: &Mat2<float> = &Matrix::identity();
let _id: &Mat2<f64> = &Matrix::identity();
}
pub trait Index<Index,Result> { }

View file

@ -9,8 +9,8 @@
// except according to those terms.
struct TwoDoubles {
r: float,
i: float
r: f64,
i: f64
}
extern "C" {

View file

@ -9,7 +9,7 @@
// except according to those terms.
pub fn main() {
static FOO: float = 10.0;
static FOO: f64 = 10.0;
match 0.0 {
0.0 .. FOO => (),

View file

@ -13,7 +13,7 @@ use std::local_data;
local_data_key!(foo: int)
mod bar {
local_data_key!(pub baz: float)
local_data_key!(pub baz: f64)
}
pub fn main() {

View file

@ -27,7 +27,7 @@ impl Trait<int> for S2 {
}
pub fn main() {
let _ = S::<int>::new::<float>(1, 1.0);
let _: S2 = Trait::<int>::new::<float>(1, 1.0);
let _ = S::<int>::new::<f64>(1, 1.0);
let _: S2 = Trait::<int>::new::<f64>(1, 1.0);
}

View file

@ -36,7 +36,6 @@ pub fn main() {
// floats
// num
assert_eq!(10f.to_int(), 10);
assert_eq!(10f32.to_int(), 10);
assert_eq!(10f64.to_int(), 10);
}

View file

@ -11,7 +11,7 @@
// Testing that calling fmt! (via info2!) doesn't complain about impure borrows
struct Big { b: @~str, c: uint, d: int, e: char,
f: float, g: bool }
f: f64, g: bool }
fn foo() {
let a = Big {

View file

@ -152,13 +152,6 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> {
true
}
fn visit_float(&mut self) -> bool {
self.align_to::<float>();
if ! self.inner.visit_float() { return false; }
self.bump_past::<float>();
true
}
fn visit_f32(&mut self) -> bool {
self.align_to::<f32>();
if ! self.inner.visit_f32() { return false; }
@ -528,7 +521,6 @@ impl TyVisitor for my_visitor {
fn visit_u32(&mut self) -> bool { true }
fn visit_u64(&mut self) -> bool { true }
fn visit_float(&mut self) -> bool { true }
fn visit_f32(&mut self) -> bool { true }
fn visit_f64(&mut self) -> bool { true }

View file

@ -54,7 +54,6 @@ impl TyVisitor for MyVisitor {
fn visit_u32(&mut self) -> bool { true }
fn visit_u64(&mut self) -> bool { true }
fn visit_float(&mut self) -> bool { true }
fn visit_f32(&mut self) -> bool { true }
fn visit_f64(&mut self) -> bool { true }

View file

@ -24,15 +24,15 @@ fn make_generic_record<A,B>(a: A, b: B) -> Pair<A,B> {
return Pair {a: a, b: b};
}
fn test05_start(f: &~fn(v: float, v: ~str) -> Pair<float, ~str>) {
let p = (*f)(22.22f, ~"Hi");
fn test05_start(f: &~fn(v: f64, v: ~str) -> Pair<f64, ~str>) {
let p = (*f)(22.22, ~"Hi");
info2!("{:?}", p.clone());
assert!(p.a == 22.22f);
assert!(p.a == 22.22);
assert!(p.b == ~"Hi");
let q = (*f)(44.44f, ~"Ho");
let q = (*f)(44.44, ~"Ho");
info2!("{:?}", q.clone());
assert!(q.a == 44.44f);
assert!(q.a == 44.44);
assert!(q.b == ~"Ho");
}
@ -42,5 +42,5 @@ fn spawn<A,B>(f: extern fn(&~fn(A,B)->Pair<A,B>)) {
}
fn test05() {
spawn::<float,~str>(test05_start);
spawn::<f64,~str>(test05_start);
}

View file

@ -16,5 +16,5 @@ extern mod mycore(name ="static_fn_inline_xc_aux");
use mycore::num;
pub fn main() {
let _1:float = num::Num2::from_int2(1i);
let _1: f64 = num::Num2::from_int2(1i);
}

View file

@ -6,5 +6,5 @@ extern mod mycore(name ="static_fn_trait_xc_aux");
use mycore::num;
pub fn main() {
let _1:float = num::Num2::from_int2(1i);
let _1: f64 = num::Num2::from_int2(1i);
}

View file

@ -2,18 +2,18 @@ pub trait Number: NumConv {
fn from<T:Number>(n: T) -> Self;
}
impl Number for float {
fn from<T:Number>(n: T) -> float { n.to_float() }
impl Number for f64 {
fn from<T:Number>(n: T) -> f64 { n.to_float() }
}
pub trait NumConv {
fn to_float(&self) -> float;
fn to_float(&self) -> f64;
}
impl NumConv for float {
fn to_float(&self) -> float { *self }
impl NumConv for f64 {
fn to_float(&self) -> f64 { *self }
}
pub fn main() {
let _: float = Number::from(0.0f);
let _: f64 = Number::from(0.0f64);
}

View file

@ -14,8 +14,8 @@ enum Foo {
b: int
},
Baz {
c: float,
d: float
c: f64,
d: f64
}
}

View file

@ -14,8 +14,8 @@ enum Foo {
y: int
},
Baz {
x: float,
y: float
x: f64,
y: f64
}
}

View file

@ -51,9 +51,9 @@ fn test2() {
b: 0b_1010_1010_u8,
c: 1.0987654321e-15_f64 };
let ff = rustrt::rust_dbg_abi_2(f);
error2!("a: {}", ff.a as float);
error2!("a: {}", ff.a as f64);
error2!("b: {}", ff.b as uint);
error2!("c: {}", ff.c as float);
error2!("c: {}", ff.c as f64);
assert_eq!(ff.a, f.c + 1.0f64);
assert_eq!(ff.b, 0xff_u8);
assert_eq!(ff.c, f.a - 1.0f64);

View file

@ -25,7 +25,6 @@ pub fn main() {
info2!("{}", 1 as int);
info2!("{}", 1 as uint);
info2!("{}", 1 as float);
info2!("{}", 1 as *libc::FILE);
info2!("{}", 1 as i8);
info2!("{}", 1 as i16);
@ -40,7 +39,6 @@ pub fn main() {
info2!("{}", 1u as int);
info2!("{}", 1u as uint);
info2!("{}", 1u as float);
info2!("{}", 1u as *libc::FILE);
info2!("{}", 1u as i8);
info2!("{}", 1u as i16);
@ -55,7 +53,6 @@ pub fn main() {
info2!("{}", 1i8 as int);
info2!("{}", 1i8 as uint);
info2!("{}", 1i8 as float);
info2!("{}", 1i8 as *libc::FILE);
info2!("{}", 1i8 as i8);
info2!("{}", 1i8 as i16);
@ -70,7 +67,6 @@ pub fn main() {
info2!("{}", 1u8 as int);
info2!("{}", 1u8 as uint);
info2!("{}", 1u8 as float);
info2!("{}", 1u8 as *libc::FILE);
info2!("{}", 1u8 as i8);
info2!("{}", 1u8 as i16);
@ -85,7 +81,6 @@ pub fn main() {
info2!("{}", 1i16 as int);
info2!("{}", 1i16 as uint);
info2!("{}", 1i16 as float);
info2!("{}", 1i16 as *libc::FILE);
info2!("{}", 1i16 as i8);
info2!("{}", 1i16 as i16);
@ -100,7 +95,6 @@ pub fn main() {
info2!("{}", 1u16 as int);
info2!("{}", 1u16 as uint);
info2!("{}", 1u16 as float);
info2!("{}", 1u16 as *libc::FILE);
info2!("{}", 1u16 as i8);
info2!("{}", 1u16 as i16);
@ -115,7 +109,6 @@ pub fn main() {
info2!("{}", 1i32 as int);
info2!("{}", 1i32 as uint);
info2!("{}", 1i32 as float);
info2!("{}", 1i32 as *libc::FILE);
info2!("{}", 1i32 as i8);
info2!("{}", 1i32 as i16);
@ -130,7 +123,6 @@ pub fn main() {
info2!("{}", 1u32 as int);
info2!("{}", 1u32 as uint);
info2!("{}", 1u32 as float);
info2!("{}", 1u32 as *libc::FILE);
info2!("{}", 1u32 as i8);
info2!("{}", 1u32 as i16);
@ -145,7 +137,6 @@ pub fn main() {
info2!("{}", 1i64 as int);
info2!("{}", 1i64 as uint);
info2!("{}", 1i64 as float);
info2!("{}", 1i64 as *libc::FILE);
info2!("{}", 1i64 as i8);
info2!("{}", 1i64 as i16);
@ -160,7 +151,6 @@ pub fn main() {
info2!("{}", 1u64 as int);
info2!("{}", 1u64 as uint);
info2!("{}", 1u64 as float);
info2!("{}", 1u64 as *libc::FILE);
info2!("{}", 1u64 as i8);
info2!("{}", 1u64 as i16);
@ -175,7 +165,6 @@ pub fn main() {
info2!("{}", 1u64 as int);
info2!("{}", 1u64 as uint);
info2!("{}", 1u64 as float);
info2!("{}", 1u64 as *libc::FILE);
info2!("{}", 1u64 as i8);
info2!("{}", 1u64 as i16);
@ -190,7 +179,6 @@ pub fn main() {
info2!("{}", true as int);
info2!("{}", true as uint);
info2!("{}", true as float);
info2!("{}", true as *libc::FILE);
info2!("{}", true as i8);
info2!("{}", true as i16);
@ -205,7 +193,6 @@ pub fn main() {
info2!("{}", 1. as int);
info2!("{}", 1. as uint);
info2!("{}", 1. as float);
info2!("{}", 1. as i8);
info2!("{}", 1. as i16);
info2!("{}", 1. as i32);
@ -219,7 +206,6 @@ pub fn main() {
info2!("{}", 1f32 as int);
info2!("{}", 1f32 as uint);
info2!("{}", 1f32 as float);
info2!("{}", 1f32 as i8);
info2!("{}", 1f32 as i16);
info2!("{}", 1f32 as i32);
@ -233,7 +219,6 @@ pub fn main() {
info2!("{}", 1f64 as int);
info2!("{}", 1f64 as uint);
info2!("{}", 1f64 as float);
info2!("{}", 1f64 as i8);
info2!("{}", 1f64 as i16);
info2!("{}", 1f64 as i32);

View file

@ -40,7 +40,7 @@ pub fn main() {
fn test_color(color: color, val: int, name: ~str) {
//assert!(unsafe::transmute(color) == val);
assert_eq!(color as int, val);
assert_eq!(color as float, val as float);
assert_eq!(color as f64, val as f64);
assert!(get_color_alt(color) == name);
assert!(get_color_if(color) == name);
}

View file

@ -20,6 +20,6 @@ fn f<T, V: A<T>>(i: V, j: uint) -> uint {
}
pub fn main () {
assert_eq!(f::<float, int>(0, 2u), 2u);
assert_eq!(f::<f64, int>(0, 2u), 2u);
assert_eq!(f::<uint, int>(0, 2u), 2u);
}

View file

@ -59,7 +59,7 @@ fn main () {
assert_eq!(0i.thing(3.14, 1), (3.14, 1));
assert_eq!(B::staticthing(&0i, 3.14, 1), (3.14, 1));
assert_eq!(B::<float>::staticthing::<int>(&0i, 3.14, 1), (3.14, 1));
assert_eq!(B::<f64>::staticthing::<int>(&0i, 3.14, 1), (3.14, 1));
assert_eq!(g(0i, 3.14, 1), (3.14, 1));
assert_eq!(g(false, 3.14, 1), (3.14, 1));

View file

@ -33,7 +33,6 @@ impl TypeExt for int {}
impl TypeExt for f32 {}
impl TypeExt for f64 {}
impl TypeExt for float {}
pub trait NumExt: TypeExt + Eq + Ord + Num + NumCast {}
@ -52,7 +51,6 @@ impl NumExt for int {}
impl NumExt for f32 {}
impl NumExt for f64 {}
impl NumExt for float {}
pub trait UnSignedExt: NumExt {}
@ -74,7 +72,6 @@ impl SignedExt for int {}
impl SignedExt for f32 {}
impl SignedExt for f64 {}
impl SignedExt for float {}
pub trait IntegerExt: NumExt {}
@ -96,7 +93,6 @@ pub trait FloatExt: NumExt + ApproxEq<Self> {}
impl FloatExt for f32 {}
impl FloatExt for f64 {}
impl FloatExt for float {}
fn test_float_ext<T:FloatExt>(n: T) { println!("{}", n < n) }

View file

@ -2,7 +2,7 @@
use std::num;
pub static FUZZY_EPSILON: float = 0.1;
pub static FUZZY_EPSILON: f64 = 0.1;
pub trait FuzzyEq<Eps> {
fn fuzzy_eq(&self, other: &Self) -> bool;

View file

@ -1,6 +1,6 @@
enum T {
A(int),
B(float)
B(f64)
}
macro_rules! test(

View file

@ -14,5 +14,5 @@
extern mod foo(name = "xcrate_address_insignificant");
fn main() {
assert_eq!(foo::foo::<float>(), foo::bar());
assert_eq!(foo::foo::<f64>(), foo::bar());
}