diff --git a/doc/rust.md b/doc/rust.md index 0ae03198f3639..2a1b30bd7fa96 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -363,19 +363,17 @@ A _floating-point literal_ has one of two forms: second decimal literal. * A single _decimal literal_ followed by an _exponent_. -By default, a floating-point literal is of type `float`. A -floating-point literal may be followed (immediately, without any -spaces) by a _floating-point suffix_, which changes the type of the -literal. There are three floating-point suffixes: `f` (for the base -`float` type), `f32`, and `f64` (the 32-bit and 64-bit floating point -types). +By default, a floating-point literal has a generic type, but will fall back to +`f64`. A floating-point literal may be followed (immediately, without any +spaces) by a _floating-point suffix_, which changes the type of the literal. +There are two floating-point suffixes: `f32`, and `f64` (the 32-bit and 64-bit +floating point types). Examples of floating-point literals of various forms: ~~~~ -123.0; // type float -0.1; // type float -3f; // type float +123.0; // type f64 +0.1; // type f64 0.1f32; // type f32 12E+99_f64; // type f64 ~~~~ @@ -1179,8 +1177,8 @@ a = Cat; Enumeration constructors can have either named or unnamed fields: ~~~~ enum Animal { - Dog (~str, float), - Cat { name: ~str, weight: float } + Dog (~str, f64), + Cat { name: ~str, weight: f64 } } let mut a: Animal = Dog(~"Cocoa", 37.2); @@ -1344,17 +1342,17 @@ For example: trait Num { fn from_int(n: int) -> Self; } -impl Num for float { - fn from_int(n: int) -> float { n as float } +impl Num for f64 { + fn from_int(n: int) -> f64 { n as f64 } } -let x: float = Num::from_int(42); +let x: f64 = Num::from_int(42); ~~~~ Traits may inherit from other traits. For example, in ~~~~ -trait Shape { fn area() -> float; } -trait Circle : Shape { fn radius() -> float; } +trait Shape { fn area() -> f64; } +trait Circle : Shape { fn radius() -> f64; } ~~~~ the syntax `Circle : Shape` means that types that implement `Circle` must also have an implementation for `Shape`. @@ -1367,9 +1365,9 @@ methods of the supertrait may be called on values of subtrait-bound type paramet Referring to the previous example of `trait Circle : Shape`: ~~~ -# trait Shape { fn area(&self) -> float; } -# trait Circle : Shape { fn radius(&self) -> float; } -fn radius_times_area(c: T) -> float { +# trait Shape { fn area(&self) -> f64; } +# trait Circle : Shape { fn radius(&self) -> f64; } +fn radius_times_area(c: T) -> f64 { // `c` is both a Circle and a Shape c.radius() * c.area() } @@ -1378,10 +1376,10 @@ fn radius_times_area(c: T) -> float { Likewise, supertrait methods may also be called on trait objects. ~~~ {.xfail-test} -# trait Shape { fn area(&self) -> float; } -# trait Circle : Shape { fn radius(&self) -> float; } -# impl Shape for int { fn area(&self) -> float { 0.0 } } -# impl Circle for int { fn radius(&self) -> float { 0.0 } } +# trait Shape { fn area(&self) -> f64; } +# trait Circle : Shape { fn radius(&self) -> f64; } +# impl Shape for int { fn area(&self) -> f64 { 0.0 } } +# impl Circle for int { fn radius(&self) -> f64 { 0.0 } } # let mycircle = 0; let mycircle: Circle = @mycircle as @Circle; @@ -1395,14 +1393,14 @@ An _implementation_ is an item that implements a [trait](#traits) for a specific Implementations are defined with the keyword `impl`. ~~~~ -# struct Point {x: float, y: float}; +# struct Point {x: f64, y: f64}; # type Surface = int; -# struct BoundingBox {x: float, y: float, width: float, height: float}; +# struct BoundingBox {x: f64, y: f64, width: f64, height: f64}; # trait Shape { fn draw(&self, Surface); fn bounding_box(&self) -> BoundingBox; } # fn do_draw_circle(s: Surface, c: Circle) { } struct Circle { - radius: float, + radius: f64, center: Point, } @@ -1970,7 +1968,7 @@ values. ~~~~~~~~ {.tuple} (0,); -(0f, 4.5f); +(0.0, 4.5); ("a", 4u, true); ~~~~~~~~ @@ -2002,12 +2000,12 @@ A _unit-like structure expression_ consists only of the [path](#paths) of a [str The following are examples of structure expressions: ~~~~ -# struct Point { x: float, y: float } -# struct TuplePoint(float, float); +# struct Point { x: f64, y: f64 } +# struct TuplePoint(f64, f64); # mod game { pub struct User<'self> { name: &'self str, age: uint, score: uint } } # struct Cookie; fn some_fn(t: T) {} -Point {x: 10f, y: 20f}; -TuplePoint(10f, 20f); +Point {x: 10.0, y: 20.0}; +TuplePoint(10.0, 20.0); let u = game::User {name: "Joe", age: 35, score: 100_000}; some_fn::(Cookie); ~~~~ @@ -2248,12 +2246,12 @@ Any other cast is unsupported and will fail to compile. An example of an `as` expression: ~~~~ -# fn sum(v: &[float]) -> float { 0.0 } -# fn len(v: &[float]) -> int { 0 } +# fn sum(v: &[f64]) -> f64 { 0.0 } +# fn len(v: &[f64]) -> int { 0 } -fn avg(v: &[float]) -> float { - let sum: float = sum(v); - let sz: float = len(v) as float; +fn avg(v: &[f64]) -> f64 { + let sum: f64 = sum(v); + let sz: f64 = len(v) as f64; return sum / sz; } ~~~~ @@ -2767,19 +2765,6 @@ size, in bits, is equal to the size of the rust type `uint` on the same target machine. -#### Machine-dependent floating point type - -The Rust type `float` is a machine-specific type equal to one of the supported -Rust floating-point machine types (`f32` or `f64`). It is the largest -floating-point type that is directly supported by hardware on the target -machine, or if the target machine has no floating-point hardware support, the -largest floating-point type supported by the software floating-point library -used to support the other floating-point machine types. - -Note that due to the preference for hardware-supported floating-point, the -type `float` may not be equal to the largest *supported* floating-point type. - - ### Textual types The types `char` and `str` hold textual data. diff --git a/doc/tutorial-borrowed-ptr.md b/doc/tutorial-borrowed-ptr.md index 1da1d046878a7..c5933eb40f764 100644 --- a/doc/tutorial-borrowed-ptr.md +++ b/doc/tutorial-borrowed-ptr.md @@ -32,7 +32,7 @@ where you would like to use data for a short time. As an example, consider a simple struct type `Point`: ~~~ -struct Point {x: float, y: float} +struct Point {x: f64, y: f64} ~~~ We can use this simple definition to allocate points in many different ways. For @@ -40,7 +40,7 @@ example, in this code, each of these three local variables contains a point, but allocated in a different place: ~~~ -# struct Point {x: float, y: float} +# struct Point {x: f64, y: f64} let on_the_stack : Point = Point {x: 3.0, y: 4.0}; let managed_box : @Point = @Point {x: 5.0, y: 1.0}; let owned_box : ~Point = ~Point {x: 7.0, y: 9.0}; @@ -59,9 +59,9 @@ function that takes the points by pointer. We can use borrowed pointers to do this: ~~~ -# struct Point {x: float, y: float} -# fn sqrt(f: float) -> float { 0f } -fn compute_distance(p1: &Point, p2: &Point) -> float { +# struct Point {x: f64, y: f64} +# fn sqrt(f: f64) -> f64 { 0.0 } +fn compute_distance(p1: &Point, p2: &Point) -> f64 { let x_d = p1.x - p2.x; let y_d = p1.y - p2.y; sqrt(x_d * x_d + y_d * y_d) @@ -71,11 +71,11 @@ fn compute_distance(p1: &Point, p2: &Point) -> float { Now we can call `compute_distance()` in various ways: ~~~ -# struct Point {x: float, y: float} +# struct Point {x: f64, y: f64} # let on_the_stack : Point = Point{x: 3.0, y: 4.0}; # let managed_box : @Point = @Point{x: 5.0, y: 1.0}; # let owned_box : ~Point = ~Point{x: 7.0, y: 9.0}; -# fn compute_distance(p1: &Point, p2: &Point) -> float { 0f } +# fn compute_distance(p1: &Point, p2: &Point) -> f64 { 0.0 } compute_distance(&on_the_stack, managed_box); compute_distance(managed_box, owned_box); ~~~ @@ -108,7 +108,7 @@ before you can make full use of it again. In the previous example, the value `on_the_stack` was defined like so: ~~~ -# struct Point {x: float, y: float} +# struct Point {x: f64, y: f64} let on_the_stack: Point = Point {x: 3.0, y: 4.0}; ~~~ @@ -118,7 +118,7 @@ functions. As a consequence, we had to explicitly take the address of convenient to move the & operator into the definition of `on_the_stack`: ~~~ -# struct Point {x: float, y: float} +# struct Point {x: f64, y: f64} let on_the_stack2: &Point = &Point {x: 3.0, y: 4.0}; ~~~ @@ -127,7 +127,7 @@ shorthand for creating a temporary and taking its address. A more verbose way to write the same code is: ~~~ -# struct Point {x: float, y: float} +# struct Point {x: f64, y: f64} let tmp = Point {x: 3.0, y: 4.0}; let on_the_stack2 : &Point = &tmp; ~~~ @@ -140,36 +140,36 @@ individual array elements. For example, consider this type definition for `rectangle`: ~~~ -struct Point {x: float, y: float} // as before -struct Size {w: float, h: float} // as before +struct Point {x: f64, y: f64} // as before +struct Size {w: f64, h: f64} // as before struct Rectangle {origin: Point, size: Size} ~~~ Now, as before, we can define rectangles in a few different ways: ~~~ -# struct Point {x: float, y: float} -# struct Size {w: float, h: float} // as before +# struct Point {x: f64, y: f64} +# struct Size {w: f64, h: f64} // as before # struct Rectangle {origin: Point, size: Size} -let rect_stack = &Rectangle {origin: Point {x: 1f, y: 2f}, - size: Size {w: 3f, h: 4f}}; -let rect_managed = @Rectangle {origin: Point {x: 3f, y: 4f}, - size: Size {w: 3f, h: 4f}}; -let rect_owned = ~Rectangle {origin: Point {x: 5f, y: 6f}, - size: Size {w: 3f, h: 4f}}; +let rect_stack = &Rectangle {origin: Point {x: 1.0, y: 2.0}, + size: Size {w: 3.0, h: 4.0}}; +let rect_managed = @Rectangle {origin: Point {x: 3.0, y: 4.0}, + size: Size {w: 3.0, h: 4.0}}; +let rect_owned = ~Rectangle {origin: Point {x: 5.0, y: 6.0}, + size: Size {w: 3.0, h: 4.0}}; ~~~ In each case, we can extract out individual subcomponents with the `&` operator. For example, I could write: ~~~ -# struct Point {x: float, y: float} // as before -# struct Size {w: float, h: float} // as before +# struct Point {x: f64, y: f64} // as before +# struct Size {w: f64, h: f64} // as before # struct Rectangle {origin: Point, size: Size} -# let rect_stack = &Rectangle {origin: Point {x: 1f, y: 2f}, size: Size {w: 3f, h: 4f}}; -# let rect_managed = @Rectangle {origin: Point {x: 3f, y: 4f}, size: Size {w: 3f, h: 4f}}; -# let rect_owned = ~Rectangle {origin: Point {x: 5f, y: 6f}, size: Size {w: 3f, h: 4f}}; -# fn compute_distance(p1: &Point, p2: &Point) -> float { 0f } +# let rect_stack = &Rectangle {origin: Point {x: 1.0, y: 2.0}, size: Size {w: 3.0, h: 4.0}}; +# let rect_managed = @Rectangle {origin: Point {x: 3.0, y: 4.0}, size: Size {w: 3.0, h: 4.0}}; +# let rect_owned = ~Rectangle {origin: Point {x: 5.0, y: 6.0}, size: Size {w: 3.0, h: 4.0}}; +# fn compute_distance(p1: &Point, p2: &Point) -> f64 { 0.0 } compute_distance(&rect_stack.origin, &rect_managed.origin); ~~~ @@ -375,10 +375,10 @@ As an example, let’s look at the following `shape` type that can represent both rectangles and circles: ~~~ -struct Point {x: float, y: float}; // as before -struct Size {w: float, h: float}; // as before +struct Point {x: f64, y: f64}; // as before +struct Size {w: f64, h: f64}; // as before enum Shape { - Circle(Point, float), // origin, radius + Circle(Point, f64), // origin, radius Rectangle(Point, Size) // upper-left, dimensions } ~~~ @@ -388,14 +388,14 @@ function takes a borrowed pointer to a shape, to avoid the need for copying. ~~~ -# struct Point {x: float, y: float}; // as before -# struct Size {w: float, h: float}; // as before +# struct Point {x: f64, y: f64}; // as before +# struct Size {w: f64, h: f64}; // as before # enum Shape { -# Circle(Point, float), // origin, radius +# Circle(Point, f64), // origin, radius # Rectangle(Point, Size) // upper-left, dimensions # } -# static tau: float = 6.28f; -fn compute_area(shape: &Shape) -> float { +# static tau: f64 = 6.28; +fn compute_area(shape: &Shape) -> f64 { match *shape { Circle(_, radius) => 0.5 * tau * radius * radius, Rectangle(_, ref size) => size.w * size.h @@ -424,10 +424,10 @@ Stack Memory +-------+ +---------------+ | shape | ------> | rectangle( | -+-------+ | {x: float, | -| size | -+ | y: float}, | -+-------+ +----> | {w: float, | - | h: float}) | ++-------+ | {x: f64, | +| size | -+ | y: f64}, | ++-------+ +----> | {w: f64, | + | h: f64}) | +---------------+ ~~~ @@ -449,16 +449,16 @@ Stack Memory +-------+ +---------------+ | shape | ------> | circle( | -+-------+ | {x: float, | -| size | -+ | y: float}, | -+-------+ +----> | float) | ++-------+ | {x: f64, | +| size | -+ | y: f64}, | ++-------+ +----> | f64) | | | +---------------+ ~~~ -As you can see, the `size` pointer would be pointing at a `float` +As you can see, the `size` pointer would be pointing at a `f64` instead of a struct. This is not good: dereferencing the second field -of a `float` as if it were a struct with two fields would be a memory +of a `f64` as if it were a struct with two fields would be a memory safety violation. So, in fact, for every `ref` binding, the compiler will impose the @@ -484,13 +484,13 @@ as we'll see, doing so requires some explicit annotation. For example, we could write a subroutine like this: ~~~ -struct Point {x: float, y: float} -fn get_x<'r>(p: &'r Point) -> &'r float { &p.x } +struct Point {x: f64, y: f64} +fn get_x<'r>(p: &'r Point) -> &'r f64 { &p.x } ~~~ Here, the function `get_x()` returns a pointer into the structure it was given. The type of the parameter (`&'r Point`) and return type -(`&'r float`) both use a new syntactic form that we have not seen so +(`&'r f64`) both use a new syntactic form that we have not seen so far. Here the identifier `r` names the lifetime of the pointer explicitly. So in effect, this function declares that it takes a pointer with lifetime `r` and returns a pointer with that same @@ -525,8 +525,8 @@ To emphasize this point, let’s look at a variation on the example, this time one that does not compile: ~~~ {.xfail-test} -struct Point {x: float, y: float} -fn get_x_sh(p: @Point) -> &float { +struct Point {x: f64, y: f64} +fn get_x_sh(p: @Point) -> &f64 { &p.x // Error reported here } ~~~ @@ -564,14 +564,14 @@ for grouping of parameters by lifetime. For example, consider this function: ~~~ -# struct Point {x: float, y: float}; // as before -# struct Size {w: float, h: float}; // as before +# struct Point {x: f64, y: f64}; // as before +# struct Size {w: f64, h: f64}; // as before # enum Shape { -# Circle(Point, float), // origin, radius +# Circle(Point, f64), // origin, radius # Rectangle(Point, Size) // upper-left, dimensions # } -# fn compute_area(shape: &Shape) -> float { 0f } -fn select<'r, T>(shape: &'r Shape, threshold: float, +# fn compute_area(shape: &Shape) -> f64 { 0.0 } +fn select<'r, T>(shape: &'r Shape, threshold: f64, a: &'r T, b: &'r T) -> &'r T { if compute_area(shape) > threshold {a} else {b} } @@ -584,20 +584,20 @@ region parameters*. This may be overly conservative, as in this example: ~~~ -# struct Point {x: float, y: float}; // as before -# struct Size {w: float, h: float}; // as before +# struct Point {x: f64, y: f64}; // as before +# struct Size {w: f64, h: f64}; // as before # enum Shape { -# Circle(Point, float), // origin, radius +# Circle(Point, f64), // origin, radius # Rectangle(Point, Size) // upper-left, dimensions # } -# fn compute_area(shape: &Shape) -> float { 0f } -# fn select<'r, T>(shape: &Shape, threshold: float, +# fn compute_area(shape: &Shape) -> f64 { 0.0 } +# fn select<'r, T>(shape: &Shape, threshold: f64, # a: &'r T, b: &'r T) -> &'r T { # if compute_area(shape) > threshold {a} else {b} # } // -+ r fn select_based_on_unit_circle<'r, T>( // |-+ B - 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., y: 0.}, 1.); // | | select(&shape, threshold, a, b) // | | @@ -621,14 +621,14 @@ the latter two. After all, the first parameter is not being returned. Here is how the new `select()` might look: ~~~ -# struct Point {x: float, y: float}; // as before -# struct Size {w: float, h: float}; // as before +# struct Point {x: f64, y: f64}; // as before +# struct Size {w: f64, h: f64}; // as before # enum Shape { -# Circle(Point, float), // origin, radius +# Circle(Point, f64), // origin, radius # Rectangle(Point, Size) // upper-left, dimensions # } -# fn compute_area(shape: &Shape) -> float { 0f } -fn select<'r, 'tmp, T>(shape: &'tmp Shape, threshold: float, +# fn compute_area(shape: &Shape) -> f64 { 0.0 } +fn select<'r, 'tmp, T>(shape: &'tmp Shape, threshold: f64, a: &'r T, b: &'r T) -> &'r T { if compute_area(shape) > threshold {a} else {b} } @@ -640,14 +640,14 @@ However, since the lifetime `tmp` is not returned, it would be more concise to just omit the named lifetime for `shape` altogether: ~~~ -# struct Point {x: float, y: float}; // as before -# struct Size {w: float, h: float}; // as before +# struct Point {x: f64, y: f64}; // as before +# struct Size {w: f64, h: f64}; // as before # enum Shape { -# Circle(Point, float), // origin, radius +# Circle(Point, f64), // origin, radius # Rectangle(Point, Size) // upper-left, dimensions # } -# fn compute_area(shape: &Shape) -> float { 0f } -fn select<'r, T>(shape: &Shape, threshold: float, +# fn compute_area(shape: &Shape) -> f64 { 0.0 } +fn select<'r, T>(shape: &Shape, threshold: f64, a: &'r T, b: &'r T) -> &'r T { if compute_area(shape) > threshold {a} else {b} } diff --git a/doc/tutorial-tasks.md b/doc/tutorial-tasks.md index 09d3469871f65..dedbc8ae5931c 100644 --- a/doc/tutorial-tasks.md +++ b/doc/tutorial-tasks.md @@ -331,12 +331,12 @@ a single large vector of floats. Each task needs the full vector to perform its # use std::rand; use extra::arc::Arc; -fn pnorm(nums: &~[float], p: uint) -> float { - nums.iter().fold(0.0, |a,b| a+(*b).pow(&(p as float)) ).pow(&(1f / (p as float))) +fn pnorm(nums: &~[f64], p: uint) -> f64 { + nums.iter().fold(0.0, |a,b| a+(*b).pow(&(p as f64)) ).pow(&(1.0 / (p as f64))) } fn main() { - let numbers = vec::from_fn(1000000, |_| rand::random::()); + let numbers = vec::from_fn(1000000, |_| rand::random::()); println!("Inf-norm = {}", *numbers.iter().max().unwrap()); let numbers_arc = Arc::new(numbers); @@ -346,7 +346,7 @@ fn main() { chan.send(numbers_arc.clone()); do spawn { - let local_arc : Arc<~[float]> = port.recv(); + let local_arc : Arc<~[f64]> = port.recv(); let task_numbers = local_arc.get(); println!("{}-norm = {}", num, pnorm(task_numbers, num)); } @@ -361,7 +361,7 @@ created by the line # use extra::arc::Arc; # use std::vec; # use std::rand; -# let numbers = vec::from_fn(1000000, |_| rand::random::()); +# let numbers = vec::from_fn(1000000, |_| rand::random::()); let numbers_arc=Arc::new(numbers); ~~~ and a clone of it is sent to each task @@ -369,7 +369,7 @@ and a clone of it is sent to each task # use extra::arc::Arc; # use std::vec; # use std::rand; -# let numbers=vec::from_fn(1000000, |_| rand::random::()); +# let numbers=vec::from_fn(1000000, |_| rand::random::()); # let numbers_arc = Arc::new(numbers); # let (port, chan) = stream(); chan.send(numbers_arc.clone()); @@ -381,11 +381,11 @@ Each task recovers the underlying data by # use extra::arc::Arc; # use std::vec; # use std::rand; -# let numbers=vec::from_fn(1000000, |_| rand::random::()); +# let numbers=vec::from_fn(1000000, |_| rand::random::()); # let numbers_arc=Arc::new(numbers); # let (port, chan) = stream(); # chan.send(numbers_arc.clone()); -# let local_arc : Arc<~[float]> = port.recv(); +# let local_arc : Arc<~[f64]> = port.recv(); let task_numbers = local_arc.get(); ~~~ and can use it as if it were local. diff --git a/doc/tutorial.md b/doc/tutorial.md index f9109fcb8ea39..64230a27637ec 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -235,13 +235,13 @@ can specify a variable's type by following it with a colon, then the type name. Static items, on the other hand, always require a type annotation. ~~~~ -static MONSTER_FACTOR: float = 57.8; +static MONSTER_FACTOR: f64 = 57.8; let monster_size = MONSTER_FACTOR * 10.0; let monster_size: int = 50; ~~~~ Local variables may shadow earlier declarations, as in the previous example: -`monster_size` was first declared as a `float`, and then a second +`monster_size` was first declared as a `f64`, and then a second `monster_size` was declared as an `int`. If you were to actually compile this example, though, the compiler would determine that the first `monster_size` is unused and issue a warning (because this situation is likely to indicate a @@ -341,10 +341,10 @@ let c = 100u; // c is a uint let d = 1000i32; // d is an i32 ~~~~ -There are three floating-point types: `float`, `f32`, and `f64`. +There are two floating-point types: `f32`, and `f64`. Floating-point numbers are written `0.0`, `1e6`, or `2.1e-4`. Like integers, floating-point literals are inferred to the correct type. -Suffixes `f`, `f32`, and `f64` can be used to create literals of a specific type. +Suffixes ``f32`, and `f64` can be used to create literals of a specific type. The keywords `true` and `false` produce literals of type `bool`. @@ -377,7 +377,7 @@ if a meaningful conversion exists, convert the result of the expression to the given type. ~~~~ -let x: float = 4.0; +let x: f64 = 4.0; let y: uint = x as uint; assert!(y == 4u); ~~~~ @@ -496,25 +496,25 @@ A powerful application of pattern matching is *destructuring*: matching in order to bind names to the contents of data types. -> ***Note:*** The following code makes use of tuples (`(float, float)`) which +> ***Note:*** The following code makes use of tuples (`(f64, f64)`) which > are explained in section 5.3. For now you can think of tuples as a list of > items. ~~~~ -use std::float; +use std::f64; use std::num::atan; -fn angle(vector: (float, float)) -> float { - let pi = float::consts::pi; +fn angle(vector: (f64, f64)) -> f64 { + let pi = f64::consts::pi; match vector { - (0f, y) if y < 0f => 1.5 * pi, - (0f, y) => 0.5 * pi, + (0.0, y) if y < 0.0 => 1.5 * pi, + (0.0, y) => 0.5 * pi, (x, y) => atan(y / x) } } ~~~~ A variable name in a pattern matches any value, *and* binds that name -to the value of the matched value inside of the arm's action. Thus, `(0f, +to the value of the matched value inside of the arm's action. Thus, `(0.0, y)` matches any tuple whose first element is zero, and binds `y` to the second element. `(x, y)` matches any two-element tuple, and binds both elements to variables. @@ -583,8 +583,8 @@ operator to access struct fields, as in `mypoint.x`. ~~~~ struct Point { - x: float, - y: float + x: f64, + y: f64 } ~~~~ @@ -597,7 +597,7 @@ With a value (say, `mypoint`) of such a type in a mutable location, you can do struct without inherited mutability would result in a type error. ~~~~ {.xfail-test} -# struct Point { x: float, y: float } +# struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 }; @@ -609,7 +609,7 @@ origin.y += 1.0; // ERROR: assigning to immutable field `Name { fieldname: pattern, ... }`: ~~~~ -# struct Point { x: float, y: float } +# struct Point { x: f64, y: f64 } # let mypoint = Point { x: 0.0, y: 0.0 }; match mypoint { Point { x: 0.0, y: yy } => { println(yy.to_str()); } @@ -625,7 +625,7 @@ Additionally, struct fields have a shorthand matching form that simply reuses the field name as the binding name. ~~~ -# struct Point { x: float, y: float } +# struct Point { x: f64, y: f64 } # let mypoint = Point { x: 0.0, y: 0.0 }; match mypoint { Point { x, _ } => { println(x.to_str()) } @@ -638,15 +638,15 @@ Enums are datatypes that have several alternate representations. For example, consider the type shown earlier: ~~~~ -# struct Point { x: float, y: float } +# struct Point { x: f64, y: f64 } enum Shape { - Circle(Point, float), + Circle(Point, f64), Rectangle(Point, Point) } ~~~~ A value of this type is either a `Circle`, in which case it contains a -`Point` struct and a float, or a `Rectangle`, in which case it contains +`Point` struct and a f64, or a `Rectangle`, in which case it contains two `Point` structs. The run-time representation of such a value includes an identifier of the actual form that it holds, much like the "tagged union" pattern in C, but with better static guarantees. @@ -654,7 +654,7 @@ includes an identifier of the actual form that it holds, much like the The above declaration will define a type `Shape` that can refer to such shapes, and two functions, `Circle` and `Rectangle`, which can be used to construct values of the type (taking arguments of the -specified types). So `Circle(Point { x: 0f, y: 0f }, 10f)` is the way to +specified types). So `Circle(Point { x: 0.0, y: 0.0 }, 10.0)` is the way to create a new circle. Enum variants need not have parameters. This `enum` declaration, @@ -697,12 +697,12 @@ get at their contents. All variant constructors can be used as patterns, as in this definition of `area`: ~~~~ -use std::float; -# struct Point {x: float, y: float} -# enum Shape { Circle(Point, float), Rectangle(Point, Point) } -fn area(sh: Shape) -> float { +use std::f64; +# struct Point {x: f64, y: f64} +# enum Shape { Circle(Point, f64), Rectangle(Point, Point) } +fn area(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) } } @@ -714,14 +714,14 @@ introduction form, nullary enum patterns are written without parentheses. ~~~~ -# struct Point { x: float, y: float } +# struct Point { x: f64, y: f64 } # enum Direction { North, East, South, West } fn point_from_direction(dir: Direction) -> Point { match dir { - North => Point { x: 0f, y: 1f }, - East => Point { x: 1f, y: 0f }, - South => Point { x: 0f, y: -1f }, - West => Point { x: -1f, y: 0f } + North => Point { x: 0.0, y: 1.0 }, + East => Point { x: 1.0, y: 0.0 }, + South => Point { x: 0.0, y: -1.0 }, + West => Point { x: -1.0, y: 0.0 } } } ~~~~ @@ -729,16 +729,16 @@ fn point_from_direction(dir: Direction) -> Point { Enum variants may also be structs. For example: ~~~~ -use std::float; -# struct Point { x: float, y: float } -# fn square(x: float) -> float { x * x } +use std::f64; +# struct Point { x: f64, y: f64 } +# fn square(x: f64) -> f64 { x * x } enum Shape { - Circle { center: Point, radius: float }, + Circle { center: Point, radius: f64 }, Rectangle { top_left: Point, bottom_right: Point } } -fn area(sh: Shape) -> float { +fn area(sh: Shape) -> f64 { match sh { - Circle { radius: radius, _ } => float::consts::pi * square(radius), + Circle { radius: radius, _ } => f64::consts::pi * square(radius), Rectangle { top_left: top_left, bottom_right: bottom_right } => { (bottom_right.x - top_left.x) * (top_left.y - bottom_right.y) } @@ -754,7 +754,7 @@ Tuples can have any arity except for 0 (though you may consider unit, `()`, as the empty tuple if you like). ~~~~ -let mytup: (int, int, float) = (10, 20, 30.0); +let mytup: (int, int, f64) = (10, 20, 30.0); match mytup { (a, b, c) => info2!("{}", a + b + (c as int)) } @@ -769,7 +769,7 @@ names. For example: ~~~~ -struct MyTup(int, int, float); +struct MyTup(int, int, f64); let mytup: MyTup = MyTup(10, 20, 30.0); match mytup { MyTup(a, b, c) => info2!("{}", a + b + (c as int)) @@ -862,7 +862,7 @@ pattern destructuring. Like `let`, argument patterns must be irrefutable, as in this example that unpacks the first value from a tuple and returns it. ~~~ -fn first((value, _): (int, float)) -> int { value } +fn first((value, _): (int, f64)) -> int { value } ~~~ # Destructors @@ -1074,8 +1074,8 @@ As an example, consider a simple struct type, `Point`: ~~~ struct Point { - x: float, - y: float + x: f64, + y: f64 } ~~~~ @@ -1084,7 +1084,7 @@ ways. For example, in this code, each of these three local variables contains a point, but allocated in a different location: ~~~ -# struct Point { x: float, y: float } +# struct Point { x: f64, y: f64 } let on_the_stack : Point = Point { x: 3.0, y: 4.0 }; let managed_box : @Point = @Point { x: 5.0, y: 1.0 }; let owned_box : ~Point = ~Point { x: 7.0, y: 9.0 }; @@ -1101,9 +1101,9 @@ bad, but often copies are expensive. So we’d like to define a function that takes the points by pointer. We can use borrowed pointers to do this: ~~~ -# struct Point { x: float, y: float } -# fn sqrt(f: float) -> float { 0f } -fn compute_distance(p1: &Point, p2: &Point) -> float { +# struct Point { x: f64, y: f64 } +# fn sqrt(f: f64) -> f64 { 0.0 } +fn compute_distance(p1: &Point, p2: &Point) -> f64 { let x_d = p1.x - p2.x; let y_d = p1.y - p2.y; sqrt(x_d * x_d + y_d * y_d) @@ -1113,11 +1113,11 @@ fn compute_distance(p1: &Point, p2: &Point) -> float { Now we can call `compute_distance()` in various ways: ~~~ -# struct Point{ x: float, y: float }; +# struct Point{ x: f64, y: f64 }; # let on_the_stack : Point = Point { x: 3.0, y: 4.0 }; # let managed_box : @Point = @Point { x: 5.0, y: 1.0 }; # let owned_box : ~Point = ~Point { x: 7.0, y: 9.0 }; -# fn compute_distance(p1: &Point, p2: &Point) -> float { 0f } +# fn compute_distance(p1: &Point, p2: &Point) -> f64 { 0.0 } compute_distance(&on_the_stack, managed_box); compute_distance(managed_box, owned_box); ~~~ @@ -1211,11 +1211,11 @@ dot operator used for field and method access. This precedence order can sometimes make code awkward and parenthesis-filled. ~~~ -# struct Point { x: float, y: float } +# struct Point { x: f64, y: f64 } # enum Shape { Rectangle(Point, Point) } # impl Shape { fn area(&self) -> int { 0 } } -let start = @Point { x: 10f, y: 20f }; -let end = ~Point { x: (*start).x + 100f, y: (*start).y + 100f }; +let start = @Point { x: 10.0, y: 20.0 }; +let end = ~Point { x: (*start).x + 100.0, y: (*start).y + 100.0 }; let rect = &Rectangle(*start, *end); let area = (*rect).area(); ~~~ @@ -1225,11 +1225,11 @@ dereferencing_ to the receiver (the value on the left-hand side of the dot), so in most cases, explicitly dereferencing the receiver is not necessary. ~~~ -# struct Point { x: float, y: float } +# struct Point { x: f64, y: f64 } # enum Shape { Rectangle(Point, Point) } # impl Shape { fn area(&self) -> int { 0 } } -let start = @Point { x: 10f, y: 20f }; -let end = ~Point { x: start.x + 100f, y: start.y + 100f }; +let start = @Point { x: 10.0, y: 20.0 }; +let end = ~Point { x: start.x + 100.0, y: start.y + 100.0 }; let rect = &Rectangle(*start, *end); let area = rect.area(); ~~~ @@ -1239,8 +1239,8 @@ automatically. For example, if you feel inclined, you could write something silly like ~~~ -# struct Point { x: float, y: float } -let point = &@~Point { x: 10f, y: 20f }; +# struct Point { x: f64, y: f64 } +let point = &@~Point { x: 10.0, y: 20.0 }; println!("{:f}", point.x); ~~~ @@ -1601,15 +1601,15 @@ methods on most Rust types, including structs and enums. As an example, let's define a `draw` method on our `Shape` enum. ~~~ -# fn draw_circle(p: Point, f: float) { } +# fn draw_circle(p: Point, f: f64) { } # fn draw_rectangle(p: Point, p: Point) { } struct Point { - x: float, - y: float + x: f64, + y: f64 } enum Shape { - Circle(Point, float), + Circle(Point, f64), Rectangle(Point, Point) } @@ -1622,7 +1622,7 @@ impl Shape { } } -let s = Circle(Point { x: 1f, y: 2f }, 3f); +let s = Circle(Point { x: 1.0, y: 2.0 }, 3.0); s.draw(); ~~~ @@ -1636,11 +1636,11 @@ or a pointer thereof. As an argument it is written either `self`, A caller must in turn have a compatible pointer type to call the method. ~~~ -# fn draw_circle(p: Point, f: float) { } +# fn draw_circle(p: Point, f: f64) { } # fn draw_rectangle(p: Point, p: Point) { } -# struct Point { x: float, y: float } +# struct Point { x: f64, y: f64 } # enum Shape { -# Circle(Point, float), +# Circle(Point, f64), # Rectangle(Point, Point) # } impl Shape { @@ -1650,7 +1650,7 @@ impl Shape { fn draw_value(self) { ... } } -let s = Circle(Point { x: 1f, y: 2f }, 3f); +let s = Circle(Point { x: 1.0, y: 2.0 }, 3.0); (@s).draw_managed(); (~s).draw_owned(); @@ -1663,11 +1663,11 @@ so the compiler will go to great lengths to convert a callee to a borrowed pointer. ~~~ -# fn draw_circle(p: Point, f: float) { } +# fn draw_circle(p: Point, f: f64) { } # fn draw_rectangle(p: Point, p: Point) { } -# struct Point { x: float, y: float } +# struct Point { x: f64, y: f64 } # enum Shape { -# Circle(Point, float), +# Circle(Point, f64), # Rectangle(Point, Point) # } # impl Shape { @@ -1676,7 +1676,7 @@ to a borrowed pointer. # fn draw_owned(~self) { ... } # fn draw_value(self) { ... } # } -# let s = Circle(Point { x: 1f, y: 2f }, 3f); +# let s = Circle(Point { x: 1.0, y: 2.0 }, 3.0); // As with typical function arguments, managed and owned pointers // are automatically converted to borrowed pointers @@ -1700,18 +1700,18 @@ These methods are the preferred way to define constructor functions. ~~~~ {.xfail-test} impl Circle { - fn area(&self) -> float { ... } - fn new(area: float) -> Circle { ... } + fn area(&self) -> f64 { ... } + fn new(area: f64) -> Circle { ... } } ~~~~ To call such a method, just prefix it with the type name and a double colon: ~~~~ -use std::float::consts::pi; -struct Circle { radius: float } +use std::f64::consts::pi; +struct Circle { radius: f64 } impl Circle { - fn new(area: float) -> Circle { Circle { radius: (area / pi).sqrt() } } + fn new(area: f64) -> Circle { Circle { radius: (area / pi).sqrt() } } } let c = Circle::new(42.5); ~~~~ @@ -1777,9 +1777,9 @@ combination of arguments of the appropriate types. The usual way is to write a function that returns `Option` instead of `T`. ~~~~ -# struct Point { x: float, y: float } -# enum Shape { Circle(Point, float), Rectangle(Point, Point) } -fn radius(shape: Shape) -> Option { +# struct Point { x: f64, y: f64 } +# enum Shape { Circle(Point, f64), Rectangle(Point, Point) } +fn radius(shape: Shape) -> Option { match shape { Circle(_, radius) => Some(radius), Rectangle(*) => None @@ -1986,16 +1986,16 @@ name and a double colon. The compiler uses type inference to decide which implementation to use. ~~~~ -use std::float::consts::pi; -trait Shape { fn new(area: float) -> Self; } -struct Circle { radius: float } -struct Square { length: float } +use std::f64::consts::pi; +trait Shape { fn new(area: f64) -> Self; } +struct Circle { radius: f64 } +struct Square { length: f64 } impl Shape for Circle { - fn new(area: float) -> Circle { Circle { radius: (area / pi).sqrt() } } + fn new(area: f64) -> Circle { Circle { radius: (area / pi).sqrt() } } } impl Shape for Square { - fn new(area: float) -> Square { Square { length: (area).sqrt() } } + fn new(area: f64) -> Square { Square { length: (area).sqrt() } } } let area = 42.5; @@ -2159,24 +2159,24 @@ For example, we can define a `Circle` trait that inherits from `Shape`. ~~~~ -trait Shape { fn area(&self) -> float; } -trait Circle : Shape { fn radius(&self) -> float; } +trait Shape { fn area(&self) -> f64; } +trait Circle : Shape { fn radius(&self) -> f64; } ~~~~ Now, we can implement `Circle` on a type only if we also implement `Shape`. ~~~~ -use std::float::consts::pi; -# 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 } +use std::f64::consts::pi; +# trait Shape { fn area(&self) -> f64; } +# trait Circle : Shape { fn radius(&self) -> f64; } +# struct Point { x: f64, y: f64 } +# fn square(x: f64) -> f64 { x * x } +struct CircleStruct { center: Point, radius: f64 } impl Circle for CircleStruct { - fn radius(&self) -> float { (self.area() / pi).sqrt() } + fn radius(&self) -> f64 { (self.area() / pi).sqrt() } } impl Shape for CircleStruct { - fn area(&self) -> float { pi * square(self.radius) } + fn area(&self) -> f64 { pi * square(self.radius) } } ~~~~ @@ -2190,9 +2190,9 @@ methods of the supertrait may be called on values of subtrait-bound type paramet Refering to the previous example of `trait Circle : Shape`: ~~~ -# trait Shape { fn area(&self) -> float; } -# trait Circle : Shape { fn radius(&self) -> float; } -fn radius_times_area(c: T) -> float { +# trait Shape { fn area(&self) -> f64; } +# trait Circle : Shape { fn radius(&self) -> f64; } +fn radius_times_area(c: T) -> f64 { // `c` is both a Circle and a Shape c.radius() * c.area() } @@ -2201,13 +2201,13 @@ fn radius_times_area(c: T) -> float { Likewise, supertrait methods may also be called on trait objects. ~~~ {.xfail-test} -use std::float::consts::pi; -# 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 { (self.area() / pi).sqrt() } } -# impl Shape for CircleStruct { fn area(&self) -> float { pi * square(self.radius) } } +use std::f64::consts::pi; +# trait Shape { fn area(&self) -> f64; } +# trait Circle : Shape { fn radius(&self) -> f64; } +# struct Point { x: f64, y: f64 } +# struct CircleStruct { center: Point, radius: f64 } +# impl Circle for CircleStruct { fn radius(&self) -> f64 { (self.area() / pi).sqrt() } } +# impl Shape for CircleStruct { fn area(&self) -> f64 { pi * square(self.radius) } } let concrete = @CircleStruct{center:Point{x:3f,y:4f},radius:5f}; let mycircle: @Circle = concrete as @Circle; @@ -2227,7 +2227,7 @@ of type `ABC` can be randomly generated and converted to a string: ~~~ #[deriving(Eq)] -struct Circle { radius: float } +struct Circle { radius: f64 } #[deriving(Rand, ToStr)] enum ABC { A, B, C } diff --git a/src/libextra/ebml.rs b/src/libextra/ebml.rs index 8cba1a417d049..0792400e857e3 100644 --- a/src/libextra/ebml.rs +++ b/src/libextra/ebml.rs @@ -422,10 +422,6 @@ pub mod reader { let bits = doc_as_u32(self.next_doc(EsF32)); unsafe { transmute(bits) } } - fn read_float(&mut self) -> float { - let bits = doc_as_u64(self.next_doc(EsFloat)); - (unsafe { transmute::(bits) }) as float - } fn read_char(&mut self) -> char { char::from_u32(doc_as_u32(self.next_doc(EsChar))).unwrap() } @@ -839,11 +835,6 @@ pub mod writer { let bits = unsafe { cast::transmute(v) }; self.wr_tagged_u32(EsF32 as uint, bits); } - fn emit_float(&mut self, v: float) { - let bits = unsafe { cast::transmute(v as f64) }; - self.wr_tagged_u64(EsFloat as uint, bits); - } - fn emit_char(&mut self, v: char) { self.wr_tagged_u32(EsChar as uint, v as u32); } diff --git a/src/libextra/flate.rs b/src/libextra/flate.rs index 616c7522a488b..a1dccf33f6cee 100644 --- a/src/libextra/flate.rs +++ b/src/libextra/flate.rs @@ -127,7 +127,7 @@ mod tests { let out = inflate_bytes(cmp); debug2!("{} bytes deflated to {} ({:.1f}% size)", input.len(), cmp.len(), - 100.0 * ((cmp.len() as float) / (input.len() as float))); + 100.0 * ((cmp.len() as f64) / (input.len() as f64))); assert_eq!(input, out); } } diff --git a/src/libextra/json.rs b/src/libextra/json.rs index fe1bbfc9ae4c8..1d8f3ffdc62aa 100644 --- a/src/libextra/json.rs +++ b/src/libextra/json.rs @@ -18,10 +18,11 @@ use std::char; use std::cast::transmute; -use std::float; +use std::f64; use std::hashmap::HashMap; use std::io::WriterUtil; use std::io; +use std::num; use std::str; use std::to_str; @@ -32,7 +33,7 @@ use treemap::TreeMap; /// Represents a json value #[deriving(Clone, Eq)] pub enum Json { - Number(float), + Number(f64), String(~str), Boolean(bool), List(List), @@ -99,17 +100,17 @@ pub fn Encoder(wr: @io::Writer) -> Encoder { impl serialize::Encoder for Encoder { fn emit_nil(&mut self) { self.wr.write_str("null") } - fn emit_uint(&mut self, v: uint) { self.emit_float(v as float); } - fn emit_u64(&mut self, v: u64) { self.emit_float(v as float); } - fn emit_u32(&mut self, v: u32) { self.emit_float(v as float); } - fn emit_u16(&mut self, v: u16) { self.emit_float(v as float); } - fn emit_u8(&mut self, v: u8) { self.emit_float(v as float); } + fn emit_uint(&mut self, v: uint) { self.emit_f64(v as f64); } + fn emit_u64(&mut self, v: u64) { self.emit_f64(v as f64); } + fn emit_u32(&mut self, v: u32) { self.emit_f64(v as f64); } + fn emit_u16(&mut self, v: u16) { self.emit_f64(v as f64); } + fn emit_u8(&mut self, v: u8) { self.emit_f64(v as f64); } - fn emit_int(&mut self, v: int) { self.emit_float(v as float); } - fn emit_i64(&mut self, v: i64) { self.emit_float(v as float); } - fn emit_i32(&mut self, v: i32) { self.emit_float(v as float); } - fn emit_i16(&mut self, v: i16) { self.emit_float(v as float); } - fn emit_i8(&mut self, v: i8) { self.emit_float(v as float); } + fn emit_int(&mut self, v: int) { self.emit_f64(v as f64); } + fn emit_i64(&mut self, v: i64) { self.emit_f64(v as f64); } + fn emit_i32(&mut self, v: i32) { self.emit_f64(v as f64); } + fn emit_i16(&mut self, v: i16) { self.emit_f64(v as f64); } + fn emit_i8(&mut self, v: i8) { self.emit_f64(v as f64); } fn emit_bool(&mut self, v: bool) { if v { @@ -119,11 +120,8 @@ impl serialize::Encoder for Encoder { } } - fn emit_f64(&mut self, v: f64) { self.emit_float(v as float); } - fn emit_f32(&mut self, v: f32) { self.emit_float(v as float); } - fn emit_float(&mut self, v: float) { - self.wr.write_str(float::to_str_digits(v, 6u)); - } + fn emit_f64(&mut self, v: f64) { self.wr.write_str(f64::to_str_digits(v, 6u)) } + fn emit_f32(&mut self, v: f32) { self.emit_f64(v as f64); } fn emit_char(&mut self, v: char) { self.emit_str(str::from_char(v)) } fn emit_str(&mut self, v: &str) { self.wr.write_str(escape_str(v)) } @@ -260,17 +258,17 @@ pub fn PrettyEncoder(wr: @io::Writer) -> PrettyEncoder { impl serialize::Encoder for PrettyEncoder { fn emit_nil(&mut self) { self.wr.write_str("null") } - fn emit_uint(&mut self, v: uint) { self.emit_float(v as float); } - fn emit_u64(&mut self, v: u64) { self.emit_float(v as float); } - fn emit_u32(&mut self, v: u32) { self.emit_float(v as float); } - fn emit_u16(&mut self, v: u16) { self.emit_float(v as float); } - fn emit_u8(&mut self, v: u8) { self.emit_float(v as float); } + fn emit_uint(&mut self, v: uint) { self.emit_f64(v as f64); } + fn emit_u64(&mut self, v: u64) { self.emit_f64(v as f64); } + fn emit_u32(&mut self, v: u32) { self.emit_f64(v as f64); } + fn emit_u16(&mut self, v: u16) { self.emit_f64(v as f64); } + fn emit_u8(&mut self, v: u8) { self.emit_f64(v as f64); } - fn emit_int(&mut self, v: int) { self.emit_float(v as float); } - fn emit_i64(&mut self, v: i64) { self.emit_float(v as float); } - fn emit_i32(&mut self, v: i32) { self.emit_float(v as float); } - fn emit_i16(&mut self, v: i16) { self.emit_float(v as float); } - fn emit_i8(&mut self, v: i8) { self.emit_float(v as float); } + fn emit_int(&mut self, v: int) { self.emit_f64(v as f64); } + fn emit_i64(&mut self, v: i64) { self.emit_f64(v as f64); } + fn emit_i32(&mut self, v: i32) { self.emit_f64(v as f64); } + fn emit_i16(&mut self, v: i16) { self.emit_f64(v as f64); } + fn emit_i8(&mut self, v: i8) { self.emit_f64(v as f64); } fn emit_bool(&mut self, v: bool) { if v { @@ -280,11 +278,8 @@ impl serialize::Encoder for PrettyEncoder { } } - fn emit_f64(&mut self, v: f64) { self.emit_float(v as float); } - fn emit_f32(&mut self, v: f32) { self.emit_float(v as float); } - fn emit_float(&mut self, v: float) { - self.wr.write_str(float::to_str_digits(v, 6u)); - } + fn emit_f64(&mut self, v: f64) { self.wr.write_str(f64::to_str_digits(v, 6u)) } + fn emit_f32(&mut self, v: f32) { self.emit_f64(v as f64); } fn emit_char(&mut self, v: char) { self.emit_str(str::from_char(v)) } fn emit_str(&mut self, v: &str) { self.wr.write_str(escape_str(v)); } @@ -585,11 +580,11 @@ impl> Parser { } fn parse_number(&mut self) -> Result { - let mut neg = 1f; + let mut neg = 1.0; if self.ch == '-' { self.bump(); - neg = -1f; + neg = -1.0; } let mut res = match self.parse_integer() { @@ -614,8 +609,8 @@ impl> Parser { Ok(Number(neg * res)) } - fn parse_integer(&mut self) -> Result { - let mut res = 0f; + fn parse_integer(&mut self) -> Result { + let mut res = 0.0; match self.ch { '0' => { @@ -631,8 +626,8 @@ impl> Parser { while !self.eof() { match self.ch { '0' .. '9' => { - res *= 10f; - res += ((self.ch as int) - ('0' as int)) as float; + res *= 10.0; + res += ((self.ch as int) - ('0' as int)) as f64; self.bump(); } @@ -646,7 +641,7 @@ impl> Parser { Ok(res) } - fn parse_decimal(&mut self, res: float) -> Result { + fn parse_decimal(&mut self, res: f64) -> Result { self.bump(); // Make sure a digit follows the decimal place. @@ -656,12 +651,12 @@ impl> Parser { } let mut res = res; - let mut dec = 1f; + let mut dec = 1.0; while !self.eof() { match self.ch { '0' .. '9' => { - dec /= 10f; - res += (((self.ch as int) - ('0' as int)) as float) * dec; + dec /= 10.0; + res += (((self.ch as int) - ('0' as int)) as f64) * dec; self.bump(); } @@ -672,7 +667,7 @@ impl> Parser { Ok(res) } - fn parse_exponent(&mut self, mut res: float) -> Result { + fn parse_exponent(&mut self, mut res: f64) -> Result { self.bump(); let mut exp = 0u; @@ -702,7 +697,7 @@ impl> Parser { } } - let exp = float::pow_with_uint(10u, exp); + let exp: f64 = num::pow_with_uint(10u, exp); if neg_exp { res /= exp; } else { @@ -892,17 +887,17 @@ impl serialize::Decoder for Decoder { } } - fn read_u64(&mut self) -> u64 { self.read_float() as u64 } - fn read_u32(&mut self) -> u32 { self.read_float() as u32 } - fn read_u16(&mut self) -> u16 { self.read_float() as u16 } - fn read_u8 (&mut self) -> u8 { self.read_float() as u8 } - fn read_uint(&mut self) -> uint { self.read_float() as uint } + fn read_u64(&mut self) -> u64 { self.read_f64() as u64 } + fn read_u32(&mut self) -> u32 { self.read_f64() as u32 } + fn read_u16(&mut self) -> u16 { self.read_f64() as u16 } + fn read_u8 (&mut self) -> u8 { self.read_f64() as u8 } + fn read_uint(&mut self) -> uint { self.read_f64() as uint } - fn read_i64(&mut self) -> i64 { self.read_float() as i64 } - fn read_i32(&mut self) -> i32 { self.read_float() as i32 } - fn read_i16(&mut self) -> i16 { self.read_float() as i16 } - fn read_i8 (&mut self) -> i8 { self.read_float() as i8 } - fn read_int(&mut self) -> int { self.read_float() as int } + fn read_i64(&mut self) -> i64 { self.read_f64() as i64 } + fn read_i32(&mut self) -> i32 { self.read_f64() as i32 } + fn read_i16(&mut self) -> i16 { self.read_f64() as i16 } + fn read_i8 (&mut self) -> i8 { self.read_f64() as i8 } + fn read_int(&mut self) -> int { self.read_f64() as int } fn read_bool(&mut self) -> bool { debug2!("read_bool"); @@ -912,15 +907,15 @@ impl serialize::Decoder for Decoder { } } - fn read_f64(&mut self) -> f64 { self.read_float() as f64 } - fn read_f32(&mut self) -> f32 { self.read_float() as f32 } - fn read_float(&mut self) -> float { - debug2!("read_float"); + fn read_f64(&mut self) -> f64 { + debug2!("read_f64"); match self.stack.pop() { Number(f) => f, value => fail2!("not a number: {:?}", value) } } + fn read_f32(&mut self) -> f32 { self.read_f64() as f32 } + fn read_f32(&mut self) -> f32 { self.read_f64() as f32 } fn read_char(&mut self) -> char { let mut v = ~[]; @@ -1192,55 +1187,51 @@ impl ToJson for @Json { } impl ToJson for int { - fn to_json(&self) -> Json { Number(*self as float) } + fn to_json(&self) -> Json { Number(*self as f64) } } impl ToJson for i8 { - fn to_json(&self) -> Json { Number(*self as float) } + fn to_json(&self) -> Json { Number(*self as f64) } } impl ToJson for i16 { - fn to_json(&self) -> Json { Number(*self as float) } + fn to_json(&self) -> Json { Number(*self as f64) } } impl ToJson for i32 { - fn to_json(&self) -> Json { Number(*self as float) } + fn to_json(&self) -> Json { Number(*self as f64) } } impl ToJson for i64 { - fn to_json(&self) -> Json { Number(*self as float) } + fn to_json(&self) -> Json { Number(*self as f64) } } impl ToJson for uint { - fn to_json(&self) -> Json { Number(*self as float) } + fn to_json(&self) -> Json { Number(*self as f64) } } impl ToJson for u8 { - fn to_json(&self) -> Json { Number(*self as float) } + fn to_json(&self) -> Json { Number(*self as f64) } } impl ToJson for u16 { - fn to_json(&self) -> Json { Number(*self as float) } + fn to_json(&self) -> Json { Number(*self as f64) } } impl ToJson for u32 { - fn to_json(&self) -> Json { Number(*self as float) } + fn to_json(&self) -> Json { Number(*self as f64) } } impl ToJson for u64 { - fn to_json(&self) -> Json { Number(*self as float) } -} - -impl ToJson for float { - fn to_json(&self) -> Json { Number(*self) } + fn to_json(&self) -> Json { Number(*self as f64) } } impl ToJson for f32 { - fn to_json(&self) -> Json { Number(*self as float) } + fn to_json(&self) -> Json { Number(*self as f64) } } impl ToJson for f64 { - fn to_json(&self) -> Json { Number(*self as float) } + fn to_json(&self) -> Json { Number(*self) } } impl ToJson for () { @@ -1374,17 +1365,17 @@ mod tests { #[test] fn test_write_number() { - assert_eq!(Number(3f).to_str(), ~"3"); - assert_eq!(Number(3f).to_pretty_str(), ~"3"); + assert_eq!(Number(3.0).to_str(), ~"3"); + assert_eq!(Number(3.0).to_pretty_str(), ~"3"); - assert_eq!(Number(3.1f).to_str(), ~"3.1"); - assert_eq!(Number(3.1f).to_pretty_str(), ~"3.1"); + assert_eq!(Number(3.1).to_str(), ~"3.1"); + assert_eq!(Number(3.1).to_pretty_str(), ~"3.1"); - assert_eq!(Number(-1.5f).to_str(), ~"-1.5"); - assert_eq!(Number(-1.5f).to_pretty_str(), ~"-1.5"); + assert_eq!(Number(-1.5).to_str(), ~"-1.5"); + assert_eq!(Number(-1.5).to_pretty_str(), ~"-1.5"); - assert_eq!(Number(0.5f).to_str(), ~"0.5"); - assert_eq!(Number(0.5f).to_pretty_str(), ~"0.5"); + assert_eq!(Number(0.5).to_str(), ~"0.5"); + assert_eq!(Number(0.5).to_pretty_str(), ~"0.5"); } #[test] @@ -1422,7 +1413,7 @@ mod tests { let longTestList = List(~[ Boolean(false), Null, - List(~[String(~"foo\nbar"), Number(3.5f)])]); + List(~[String(~"foo\nbar"), Number(3.5)])]); assert_eq!(longTestList.to_str(), ~"[false,null,[\"foo\\nbar\",3.5]]"); @@ -1649,45 +1640,45 @@ mod tests { assert_eq!(from_str("1e+"), Err(Error {line: 1u, col: 4u, msg: @~"invalid number"})); - assert_eq!(from_str("3"), Ok(Number(3f))); - assert_eq!(from_str("3.1"), Ok(Number(3.1f))); - assert_eq!(from_str("-1.2"), Ok(Number(-1.2f))); - assert_eq!(from_str("0.4"), Ok(Number(0.4f))); - assert_eq!(from_str("0.4e5"), Ok(Number(0.4e5f))); - assert_eq!(from_str("0.4e+15"), Ok(Number(0.4e15f))); - assert_eq!(from_str("0.4e-01"), Ok(Number(0.4e-01f))); - assert_eq!(from_str(" 3 "), Ok(Number(3f))); + assert_eq!(from_str("3"), Ok(Number(3.0))); + assert_eq!(from_str("3.1"), Ok(Number(3.1))); + assert_eq!(from_str("-1.2"), Ok(Number(-1.2))); + assert_eq!(from_str("0.4"), Ok(Number(0.4))); + assert_eq!(from_str("0.4e5"), Ok(Number(0.4e5))); + assert_eq!(from_str("0.4e+15"), Ok(Number(0.4e15))); + assert_eq!(from_str("0.4e-01"), Ok(Number(0.4e-01))); + assert_eq!(from_str(" 3 "), Ok(Number(3.0))); } #[test] fn test_decode_numbers() { let mut decoder = Decoder(from_str("3").unwrap()); - let v: float = Decodable::decode(&mut decoder); - assert_eq!(v, 3f); + let v: f64 = Decodable::decode(&mut decoder); + assert_eq!(v, 3.0); let mut decoder = Decoder(from_str("3.1").unwrap()); - let v: float = Decodable::decode(&mut decoder); - assert_eq!(v, 3.1f); + let v: f64 = Decodable::decode(&mut decoder); + assert_eq!(v, 3.1); let mut decoder = Decoder(from_str("-1.2").unwrap()); - let v: float = Decodable::decode(&mut decoder); - assert_eq!(v, -1.2f); + let v: f64 = Decodable::decode(&mut decoder); + assert_eq!(v, -1.2); let mut decoder = Decoder(from_str("0.4").unwrap()); - let v: float = Decodable::decode(&mut decoder); - assert_eq!(v, 0.4f); + let v: f64 = Decodable::decode(&mut decoder); + assert_eq!(v, 0.4); let mut decoder = Decoder(from_str("0.4e5").unwrap()); - let v: float = Decodable::decode(&mut decoder); - assert_eq!(v, 0.4e5f); + let v: f64 = Decodable::decode(&mut decoder); + assert_eq!(v, 0.4e5); let mut decoder = Decoder(from_str("0.4e15").unwrap()); - let v: float = Decodable::decode(&mut decoder); - assert_eq!(v, 0.4e15f); + let v: f64 = Decodable::decode(&mut decoder); + assert_eq!(v, 0.4e15); let mut decoder = Decoder(from_str("0.4e-01").unwrap()); - let v: float = Decodable::decode(&mut decoder); - assert_eq!(v, 0.4e-01f); + let v: f64 = Decodable::decode(&mut decoder); + assert_eq!(v, 0.4e-01); } #[test] @@ -1769,11 +1760,11 @@ mod tests { assert_eq!(from_str("[ false ]"), Ok(List(~[Boolean(false)]))); assert_eq!(from_str("[null]"), Ok(List(~[Null]))); assert_eq!(from_str("[3, 1]"), - Ok(List(~[Number(3f), Number(1f)]))); + Ok(List(~[Number(3.0), Number(1.0)]))); assert_eq!(from_str("\n[3, 2]\n"), - Ok(List(~[Number(3f), Number(2f)]))); + Ok(List(~[Number(3.0), Number(2.0)]))); assert_eq!(from_str("[2, [4, 1]]"), - Ok(List(~[Number(2f), List(~[Number(4f), Number(1f)])]))); + Ok(List(~[Number(2.0), List(~[Number(4.0), Number(1.0)])]))); } #[test] @@ -1855,7 +1846,7 @@ mod tests { assert_eq!(from_str("{}").unwrap(), mk_object([])); assert_eq!(from_str("{\"a\": 3}").unwrap(), - mk_object([(~"a", Number(3.0f))])); + mk_object([(~"a", Number(3.0))])); assert_eq!(from_str( "{ \"a\": null, \"b\" : true }").unwrap(), @@ -1882,7 +1873,7 @@ mod tests { "]" + "}").unwrap(), mk_object([ - (~"a", Number(1.0f)), + (~"a", Number(1.0)), (~"b", List(~[ Boolean(true), String(~"foo\nbar"), diff --git a/src/libextra/num/complex.rs b/src/libextra/num/complex.rs index 8943e2ac012df..58af80fefb787 100644 --- a/src/libextra/num/complex.rs +++ b/src/libextra/num/complex.rs @@ -30,7 +30,6 @@ pub struct Cmplx { im: T } -pub type Complex = Cmplx; pub type Complex32 = Cmplx; pub type Complex64 = Cmplx; @@ -196,25 +195,25 @@ mod test { use super::*; use std::num::{Zero,One,Real}; - pub static _0_0i : Complex = Cmplx { re: 0f, im: 0f }; - pub static _1_0i : Complex = Cmplx { re: 1f, im: 0f }; - pub static _1_1i : Complex = Cmplx { re: 1f, im: 1f }; - pub static _0_1i : Complex = Cmplx { re: 0f, im: 1f }; - pub static _neg1_1i : Complex = Cmplx { re: -1f, im: 1f }; - pub static _05_05i : Complex = Cmplx { re: 0.5f, im: 0.5f }; - pub static all_consts : [Complex, .. 5] = [_0_0i, _1_0i, _1_1i, _neg1_1i, _05_05i]; + pub static _0_0i : Complex64 = Cmplx { re: 0.0, im: 0.0 }; + pub static _1_0i : Complex64 = Cmplx { re: 1.0, im: 0.0 }; + pub static _1_1i : Complex64 = Cmplx { re: 1.0, im: 1.0 }; + pub static _0_1i : Complex64 = Cmplx { re: 0.0, im: 1.0 }; + pub static _neg1_1i : Complex64 = Cmplx { re: -1.0, im: 1.0 }; + pub static _05_05i : Complex64 = Cmplx { re: 0.5, im: 0.5 }; + pub static all_consts : [Complex64, .. 5] = [_0_0i, _1_0i, _1_1i, _neg1_1i, _05_05i]; #[test] fn test_consts() { // check our constants are what Cmplx::new creates - fn test(c : Complex, r : float, i: float) { + fn test(c : Complex64, r : f64, i: f64) { assert_eq!(c, Cmplx::new(r,i)); } - test(_0_0i, 0f, 0f); - test(_1_0i, 1f, 0f); - test(_1_1i, 1f, 1f); - test(_neg1_1i, -1f, 1f); - test(_05_05i, 0.5f, 0.5f); + test(_0_0i, 0.0, 0.0); + test(_1_0i, 1.0, 0.0); + test(_1_1i, 1.0, 1.0); + test(_neg1_1i, -1.0, 1.0); + test(_05_05i, 0.5, 0.5); assert_eq!(_0_0i, Zero::zero()); assert_eq!(_1_0i, One::one()); @@ -224,23 +223,23 @@ mod test { #[ignore(cfg(target_arch = "x86"))] // FIXME #7158: (maybe?) currently failing on x86. fn test_norm() { - fn test(c: Complex, ns: float) { + fn test(c: Complex64, ns: f64) { assert_eq!(c.norm_sqr(), ns); assert_eq!(c.norm(), ns.sqrt()) } - test(_0_0i, 0f); - test(_1_0i, 1f); - test(_1_1i, 2f); - test(_neg1_1i, 2f); - test(_05_05i, 0.5f); + test(_0_0i, 0.0); + test(_1_0i, 1.0); + test(_1_1i, 2.0); + test(_neg1_1i, 2.0); + test(_05_05i, 0.5); } #[test] fn test_scale_unscale() { - assert_eq!(_05_05i.scale(2f), _1_1i); - assert_eq!(_1_1i.unscale(2f), _05_05i); + assert_eq!(_05_05i.scale(2.0), _1_1i); + assert_eq!(_1_1i.unscale(2.0), _05_05i); for &c in all_consts.iter() { - assert_eq!(c.scale(2f).unscale(2f), c); + assert_eq!(c.scale(2.0).unscale(2.0), c); } } @@ -268,18 +267,18 @@ mod test { #[test] fn test_arg() { - fn test(c: Complex, arg: float) { + fn test(c: Complex64, arg: f64) { assert!(c.arg().approx_eq(&arg)) } - test(_1_0i, 0f); - test(_1_1i, 0.25f * Real::pi()); - test(_neg1_1i, 0.75f * Real::pi()); - test(_05_05i, 0.25f * Real::pi()); + test(_1_0i, 0.0); + test(_1_1i, 0.25 * Real::pi()); + test(_neg1_1i, 0.75 * Real::pi()); + test(_05_05i, 0.25 * Real::pi()); } #[test] fn test_polar_conv() { - fn test(c: Complex) { + fn test(c: Complex64) { let (r, theta) = c.to_polar(); assert!((c - Cmplx::from_polar(&r, &theta)).norm() < 1e-6); } @@ -316,7 +315,7 @@ mod test { #[test] fn test_mul() { - assert_eq!(_05_05i * _05_05i, _0_1i.unscale(2f)); + assert_eq!(_05_05i * _05_05i, _0_1i.unscale(2.0)); assert_eq!(_1_1i * _0_1i, _neg1_1i); // i^2 & i^4 @@ -349,7 +348,7 @@ mod test { #[test] fn test_to_str() { - fn test(c : Complex, s: ~str) { + fn test(c : Complex64, s: ~str) { assert_eq!(c.to_str(), s); } test(_0_0i, ~"0+0i"); diff --git a/src/libextra/serialize.rs b/src/libextra/serialize.rs index c44505694b13d..fb87414c8c364 100644 --- a/src/libextra/serialize.rs +++ b/src/libextra/serialize.rs @@ -41,7 +41,6 @@ pub trait Encoder { fn emit_i16(&mut self, v: i16); fn emit_i8(&mut self, v: i8); fn emit_bool(&mut self, v: bool); - fn emit_float(&mut self, v: float); fn emit_f64(&mut self, v: f64); fn emit_f32(&mut self, v: f32); fn emit_char(&mut self, v: char); @@ -108,7 +107,6 @@ pub trait Decoder { fn read_bool(&mut self) -> bool; fn read_f64(&mut self) -> f64; fn read_f32(&mut self) -> f32; - fn read_float(&mut self) -> float; fn read_char(&mut self) -> char; fn read_str(&mut self) -> ~str; @@ -326,18 +324,6 @@ impl Decodable for @str { } } -impl Encodable for float { - fn encode(&self, s: &mut S) { - s.emit_float(*self) - } -} - -impl Decodable for float { - fn decode(d: &mut D) -> float { - d.read_float() - } -} - impl Encodable for f32 { fn encode(&self, s: &mut S) { s.emit_f32(*self) diff --git a/src/libextra/sort.rs b/src/libextra/sort.rs index 5293a2c3fd7ce..e1230070836c0 100644 --- a/src/libextra/sort.rs +++ b/src/libextra/sort.rs @@ -915,13 +915,13 @@ mod test_tim_sort { #[deriving(Clone)] struct CVal { - val: float, + val: f64, } impl Ord for CVal { fn lt(&self, other: &CVal) -> bool { let mut rng = rand::rng(); - if rng.gen::() > 0.995 { + if rng.gen::() > 0.995 { fail2!("It's happening!!!"); } (*self).val < other.val @@ -1054,7 +1054,7 @@ mod big_tests { for i in range(lo, hi) { let n = 1 << i; - let mut arr: ~[float] = do vec::from_fn(n) |_i| { + let mut arr: ~[f64] = do vec::from_fn(n) |_i| { rng.gen() }; @@ -1106,7 +1106,7 @@ mod big_tests { isSorted(arr); let half = n / 2; - let mut arr = makeRange(half).map(|i| *i as float); + let mut arr = makeRange(half).map(|i| *i as f64); tim_sort(arr); // !sort isSorted(arr); } @@ -1125,7 +1125,7 @@ mod big_tests { for i in range(lo, hi) { let n = 1 << i; - let arr: ~[@float] = do vec::from_fn(n) |_i| { + let arr: ~[@f64] = do vec::from_fn(n) |_i| { @rng.gen() }; let mut arr = arr; @@ -1178,7 +1178,7 @@ mod big_tests { isSorted(arr); let half = n / 2; - let mut arr = makeRange(half).map(|i| @(*i as float)); + let mut arr = makeRange(half).map(|i| @(*i as f64)); tim_sort(arr); // !sort isSorted(arr); } diff --git a/src/libextra/test.rs b/src/libextra/test.rs index 16937e38695b7..9e30e5bcaabd5 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -485,14 +485,14 @@ impl ConsoleTestState { self.out.write_str(*k); self.out.write_str(": "); self.write_improved(); - self.out.write_line(format!(" by {:.2f}%", pct as float)) + self.out.write_line(format!(" by {:.2f}%", pct as f64)) } Regression(pct) => { regressed += 1; self.out.write_str(*k); self.out.write_str(": "); self.write_regressed(); - self.out.write_line(format!(" by {:.2f}%", pct as float)) + self.out.write_line(format!(" by {:.2f}%", pct as f64)) } } } @@ -519,7 +519,7 @@ impl ConsoleTestState { None => (), Some(pct) => self.out.write_str(format!("with noise-tolerance forced to: {}%%\n", - pct as float)) + pct as f64)) } let (diff, ok) = self.metrics.ratchet(pth, ratchet_pct); self.write_metric_diff(&diff); @@ -551,8 +551,8 @@ pub fn fmt_metrics(mm: &MetricMap) -> ~str { let v : ~[~str] = mm.iter() .map(|(k,v)| format!("{}: {} (+/- {})", *k, - v.value as float, - v.noise as float)) + v.value as f64, + v.noise as f64)) .collect(); v.connect(", ") } @@ -878,8 +878,8 @@ fn calc_result(desc: &TestDesc, task_succeeded: bool) -> TestResult { impl ToJson for Metric { fn to_json(&self) -> json::Json { let mut map = ~TreeMap::new(); - map.insert(~"value", json::Number(self.value as float)); - map.insert(~"noise", json::Number(self.noise as float)); + map.insert(~"value", json::Number(self.value as f64)); + map.insert(~"noise", json::Number(self.noise as f64)); json::Object(map) } } @@ -1083,9 +1083,9 @@ impl BenchHarness { debug2!("{} samples, median {}, MAD={}, MADP={}", samples.len(), - summ.median as float, - summ.median_abs_dev as float, - summ.median_abs_dev_pct as float); + summ.median as f64, + summ.median_abs_dev as f64, + summ.median_abs_dev_pct as f64); let now = precise_time_ns(); let loop_run = now - loop_start; diff --git a/src/libextra/time.rs b/src/libextra/time.rs index 7f08fcd908aea..b1fe0bc6d7c4e 100644 --- a/src/libextra/time.rs +++ b/src/libextra/time.rs @@ -92,8 +92,8 @@ pub fn precise_time_ns() -> u64 { * Returns the current value of a high-resolution performance counter * in seconds since an unspecified epoch. */ -pub fn precise_time_s() -> float { - return (precise_time_ns() as float) / 1000000000.; +pub fn precise_time_s() -> f64 { + return (precise_time_ns() as f64) / 1000000000.; } pub fn tzset() { @@ -905,7 +905,7 @@ fn do_strftime(format: &str, tm: &Tm) -> ~str { mod tests { use super::*; - use std::float; + use std::f64; use std::os; use std::result::{Err, Ok}; @@ -934,7 +934,7 @@ mod tests { let s0 = precise_time_s(); let ns1 = precise_time_ns(); - debug2!("s0={} sec", float::to_str_digits(s0, 9u)); + debug2!("s0={} sec", f64::to_str_digits(s0, 9u)); assert!(s0 > 0.); let ns0 = (s0 * 1000000000.) as u64; debug2!("ns0={:?} ns", ns0); diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 76f48577fe672..970f567359fee 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -603,11 +603,11 @@ pub fn build_target_config(sopts: @session::options, None => early_error(demitter, ~"unknown architecture: " + sopts.target_triple) }; - let (int_type, uint_type, float_type) = match arch { - abi::X86 => (ast::ty_i32, ast::ty_u32, ast::ty_f64), - abi::X86_64 => (ast::ty_i64, ast::ty_u64, ast::ty_f64), - abi::Arm => (ast::ty_i32, ast::ty_u32, ast::ty_f64), - abi::Mips => (ast::ty_i32, ast::ty_u32, ast::ty_f64) + let (int_type, uint_type) = match arch { + abi::X86 => (ast::ty_i32, ast::ty_u32), + abi::X86_64 => (ast::ty_i64, ast::ty_u64), + abi::Arm => (ast::ty_i32, ast::ty_u32), + abi::Mips => (ast::ty_i32, ast::ty_u32) }; let target_triple = sopts.target_triple.clone(); let target_strs = match arch { @@ -622,7 +622,6 @@ pub fn build_target_config(sopts: @session::options, target_strs: target_strs, int_type: int_type, uint_type: uint_type, - float_type: float_type }; return target_cfg; } diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index 892715c62cea1..066def72b471e 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -19,7 +19,7 @@ use metadata; use middle::lint; use syntax::ast::NodeId; -use syntax::ast::{int_ty, uint_ty, float_ty}; +use syntax::ast::{int_ty, uint_ty}; use syntax::codemap::Span; use syntax::diagnostic; use syntax::parse::ParseSess; @@ -47,7 +47,6 @@ pub struct config { target_strs: target_strs::t, int_type: int_ty, uint_type: uint_ty, - float_type: float_ty } pub static verbose: uint = 1 << 0; diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index b44051ef56058..d7a544320c26e 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -304,7 +304,6 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t { 'b' => return ty::mk_bool(), 'i' => return ty::mk_int(), 'u' => return ty::mk_uint(), - 'l' => return ty::mk_float(), 'M' => { match next(st) { 'b' => return ty::mk_mach_uint(ast::ty_u8), diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index 09c776a9fab5d..146e3cd920095 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -260,7 +260,6 @@ fn enc_sty(w: @io::Writer, cx: @ctxt, st: &ty::sty) { } ty::ty_float(t) => { match t { - ty_f => w.write_char('l'), ty_f32 => w.write_str(&"Mf"), ty_f64 => w.write_str(&"MF"), } diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index f2bfc6fb4ec2e..86a604b010472 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -115,9 +115,9 @@ pub fn check_crate( return (bccx.root_map, bccx.write_guard_map); fn make_stat(bccx: &mut BorrowckCtxt, stat: uint) -> ~str { - let stat_f = stat as float; - let total = bccx.stats.guaranteed_paths as float; - format!("{} ({:.0f}%)", stat , stat_f * 100f / total) + let stat_f = stat as f64; + let total = bccx.stats.guaranteed_paths as f64; + format!("{} ({:.0f}%)", stat , stat_f * 100.0 / total) } } diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index bba3ca9f212a9..d13493c0a0297 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -475,9 +475,9 @@ pub fn lit_to_const(lit: &lit) -> const_val { lit_int(n, _) => const_int(n), lit_uint(n, _) => const_uint(n), lit_int_unsuffixed(n) => const_int(n), - lit_float(n, _) => const_float(from_str::(n).unwrap() as f64), + lit_float(n, _) => const_float(from_str::(n).unwrap() as f64), lit_float_unsuffixed(n) => - const_float(from_str::(n).unwrap() as f64), + const_float(from_str::(n).unwrap() as f64), lit_nil => const_int(0i64), lit_bool(b) => const_bool(b) } diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 4b5141f1630e0..b1984b920afc6 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -772,7 +772,6 @@ pub fn PrimitiveTypeTable() -> PrimitiveTypeTable { table.intern("bool", ty_bool); table.intern("char", ty_char); - table.intern("float", ty_float(ty_f)); table.intern("f32", ty_float(ty_f32)); table.intern("f64", ty_float(ty_f64)); table.intern("int", ty_int(ty_i)); diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index aa56631438638..25d600de1e92b 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -56,12 +56,12 @@ pub fn const_lit(cx: &mut CrateContext, e: &ast::Expr, lit: ast::lit) ty_to_str(cx.tcx, lit_int_ty))) } } - ast::lit_float(fs, t) => C_floating(fs, Type::float_from_ty(cx, t)), + ast::lit_float(fs, t) => C_floating(fs, Type::float_from_ty(t)), ast::lit_float_unsuffixed(fs) => { let lit_float_ty = ty::node_id_to_type(cx.tcx, e.id); match ty::get(lit_float_ty).sty { ty::ty_float(t) => { - C_floating(fs, Type::float_from_ty(cx, t)) + C_floating(fs, Type::float_from_ty(t)) } _ => { cx.sess.span_bug(lit.span, diff --git a/src/librustc/middle/trans/context.rs b/src/librustc/middle/trans/context.rs index d2a3557d85b9e..3125155d0c793 100644 --- a/src/librustc/middle/trans/context.rs +++ b/src/librustc/middle/trans/context.rs @@ -109,7 +109,6 @@ pub struct CrateContext { upcalls: @upcall::Upcalls, tydesc_type: Type, int_type: Type, - float_type: Type, opaque_vec_type: Type, builder: BuilderRef_res, crate_map: ValueRef, @@ -156,7 +155,6 @@ impl CrateContext { base::declare_dbg_intrinsics(llmod, &mut intrinsics); } let int_type = Type::int(targ_cfg.arch); - let float_type = Type::float(targ_cfg.arch); let tydesc_type = Type::tydesc(targ_cfg.arch); let opaque_vec_type = Type::opaque_vec(targ_cfg.arch); @@ -234,7 +232,6 @@ impl CrateContext { upcalls: upcall::declare_upcalls(targ_cfg, llmod), tydesc_type: tydesc_type, int_type: int_type, - float_type: float_type, opaque_vec_type: opaque_vec_type, builder: BuilderRef_res(llvm::LLVMCreateBuilderInContext(llcx)), crate_map: crate_map, diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 3f4c2e8abc586..ded61f975db80 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -1046,7 +1046,6 @@ fn basic_type_metadata(cx: &mut CrateContext, t: ty::t) -> DIType { ast::ty_u64 => (~"u64", DW_ATE_unsigned) }, ty::ty_float(float_ty) => match float_ty { - ast::ty_f => (~"float", DW_ATE_float), ast::ty_f32 => (~"f32", DW_ATE_float), ast::ty_f64 => (~"f64", DW_ATE_float) }, diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs index b63533b1559d3..1ab9e4581f28c 100644 --- a/src/librustc/middle/trans/reflect.rs +++ b/src/librustc/middle/trans/reflect.rs @@ -168,7 +168,6 @@ impl Reflector { ty::ty_uint(ast::ty_u16) => self.leaf("u16"), ty::ty_uint(ast::ty_u32) => self.leaf("u32"), ty::ty_uint(ast::ty_u64) => self.leaf("u64"), - ty::ty_float(ast::ty_f) => self.leaf("float"), ty::ty_float(ast::ty_f32) => self.leaf("f32"), ty::ty_float(ast::ty_f64) => self.leaf("f64"), diff --git a/src/librustc/middle/trans/type_.rs b/src/librustc/middle/trans/type_.rs index 4a7351c207dc6..1c2445dd6316e 100644 --- a/src/librustc/middle/trans/type_.rs +++ b/src/librustc/middle/trans/type_.rs @@ -136,9 +136,8 @@ impl Type { } } - pub fn float_from_ty(ctx: &CrateContext, t: ast::float_ty) -> Type { + pub fn float_from_ty(t: ast::float_ty) -> Type { match t { - ast::ty_f => ctx.float_type, ast::ty_f32 => Type::f32(), ast::ty_f64 => Type::f64() } diff --git a/src/librustc/middle/trans/type_of.rs b/src/librustc/middle/trans/type_of.rs index 72b7281148c3d..3d5ebefcccbef 100644 --- a/src/librustc/middle/trans/type_of.rs +++ b/src/librustc/middle/trans/type_of.rs @@ -111,7 +111,7 @@ pub fn sizing_type_of(cx: &mut CrateContext, t: ty::t) -> Type { ty::ty_char => Type::char(), ty::ty_int(t) => Type::int_from_ty(cx, t), ty::ty_uint(t) => Type::uint_from_ty(cx, t), - ty::ty_float(t) => Type::float_from_ty(cx, t), + ty::ty_float(t) => Type::float_from_ty(t), ty::ty_estr(ty::vstore_uniq) | ty::ty_estr(ty::vstore_box) | @@ -199,7 +199,7 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type { ty::ty_char => Type::char(), ty::ty_int(t) => Type::int_from_ty(cx, t), ty::ty_uint(t) => Type::uint_from_ty(cx, t), - ty::ty_float(t) => Type::float_from_ty(cx, t), + ty::ty_float(t) => Type::float_from_ty(t), ty::ty_estr(ty::vstore_uniq) => { Type::vec(cx.sess.targ_cfg.arch, &Type::i8()).ptr_to() } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index ef6809c15c895..84ebda5db5c4a 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -583,7 +583,6 @@ mod primitives { def_prim_ty!(TY_U16, super::ty_uint(ast::ty_u16), 10) def_prim_ty!(TY_U32, super::ty_uint(ast::ty_u32), 11) def_prim_ty!(TY_U64, super::ty_uint(ast::ty_u64), 12) - def_prim_ty!(TY_FLOAT, super::ty_float(ast::ty_f), 13) def_prim_ty!(TY_F32, super::ty_float(ast::ty_f32), 14) def_prim_ty!(TY_F64, super::ty_float(ast::ty_f64), 15) @@ -1121,9 +1120,6 @@ pub fn mk_i32() -> t { mk_prim_t(&primitives::TY_I32) } #[inline] pub fn mk_i64() -> t { mk_prim_t(&primitives::TY_I64) } -#[inline] -pub fn mk_float() -> t { mk_prim_t(&primitives::TY_FLOAT) } - #[inline] pub fn mk_f32() -> t { mk_prim_t(&primitives::TY_F32) } @@ -1167,7 +1163,6 @@ pub fn mk_mach_uint(tm: ast::uint_ty) -> t { pub fn mk_mach_float(tm: ast::float_ty) -> t { match tm { - ast::ty_f => mk_float(), ast::ty_f32 => mk_f32(), ast::ty_f64 => mk_f64(), } @@ -2560,7 +2555,7 @@ pub fn type_is_signed(ty: t) -> bool { pub fn type_is_machine(ty: t) -> bool { match get(ty).sty { - ty_int(ast::ty_i) | ty_uint(ast::ty_u) | ty_float(ast::ty_f) => false, + ty_int(ast::ty_i) | ty_uint(ast::ty_u) => false, ty_int(*) | ty_uint(*) | ty_float(*) => true, _ => false } diff --git a/src/librustc/middle/typeck/infer/resolve.rs b/src/librustc/middle/typeck/infer/resolve.rs index 57e0ecf874532..dcb0e6fbd413d 100644 --- a/src/librustc/middle/typeck/infer/resolve.rs +++ b/src/librustc/middle/typeck/infer/resolve.rs @@ -269,9 +269,9 @@ impl ResolveState { Some(t) => ty::mk_mach_float(t), None => { if self.should(force_fvar) { - // As a last resort, default to float. - let ty = ty::mk_float(); - self.infcx.set(vid, Root(Some(ast::ty_f), node.rank)); + // As a last resort, default to f64. + let ty = ty::mk_f64(); + self.infcx.set(vid, Root(Some(ast::ty_f64), node.rank)); ty } else { ty::mk_float_var(self.infcx.tcx, vid) diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index bbca28f134f8d..21517e42169c5 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -417,7 +417,6 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str { ty_int(t) => ast_util::int_ty_to_str(t), ty_uint(ast::ty_u) => ~"uint", ty_uint(t) => ast_util::uint_ty_to_str(t), - ty_float(ast::ty_f) => ~"float", ty_float(t) => ast_util::float_ty_to_str(t), ty_box(ref tm) => ~"@" + mt_to_str(cx, tm), ty_uniq(ref tm) => ~"~" + mt_to_str(cx, tm), diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 66796252770d4..acbed7f4120f8 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -233,7 +233,6 @@ impl fmt::Default for clean::Type { ast::ty_uint(ast::ty_u16) => "u16", ast::ty_uint(ast::ty_u32) => "u32", ast::ty_uint(ast::ty_u64) => "u64", - ast::ty_float(ast::ty_f) => "float", ast::ty_float(ast::ty_f32) => "f32", ast::ty_float(ast::ty_f64) => "f64", ast::ty_str => "str", diff --git a/src/libstd/clone.rs b/src/libstd/clone.rs index bd5bfb197b2d1..701be1b3dfa97 100644 --- a/src/libstd/clone.rs +++ b/src/libstd/clone.rs @@ -89,7 +89,6 @@ clone_impl!(u16) clone_impl!(u32) clone_impl!(u64) -clone_impl!(float) clone_impl!(f32) clone_impl!(f64) @@ -169,7 +168,6 @@ deep_clone_impl!(u16) deep_clone_impl!(u32) deep_clone_impl!(u64) -deep_clone_impl!(float) deep_clone_impl!(f32) deep_clone_impl!(f64) @@ -241,9 +239,9 @@ fn test_extern_fn_clone() { trait Empty {} impl Empty for int {} - fn test_fn_a() -> float { 1.0 } + fn test_fn_a() -> f64 { 1.0 } fn test_fn_b(x: T) -> T { x } - fn test_fn_c(_: int, _: float, _: ~[int], _: int, _: int, _: int) {} + fn test_fn_c(_: int, _: f64, _: ~[int], _: int, _: int, _: int) {} let _ = test_fn_a.clone(); let _ = test_fn_b::.clone(); diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index ba3a3bb4cc863..a03f21d69c8d5 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -1035,7 +1035,6 @@ macro_rules! floating(($ty:ident) => { } } }) -floating!(float) floating!(f32) floating!(f64) @@ -1096,7 +1095,6 @@ delegate!(~str to String) delegate!(&'self str to String) delegate!(bool to Bool) delegate!(char to Char) -delegate!(float to Float) delegate!(f32 to Float) delegate!(f64 to Float) diff --git a/src/libstd/iter.rs b/src/libstd/iter.rs index f1e0eff5616c9..6043f7e3f52e4 100644 --- a/src/libstd/iter.rs +++ b/src/libstd/iter.rs @@ -2269,12 +2269,12 @@ mod tests { #[test] fn test_iterator_scan() { // test the type inference - fn add(old: &mut int, new: &uint) -> Option { + fn add(old: &mut int, new: &uint) -> Option { *old += *new as int; - Some(*old as float) + Some(*old as f64) } let xs = [0u, 1, 2, 3, 4]; - let ys = [0f, 1f, 3f, 6f, 10f]; + let ys = [0f64, 1.0, 3.0, 6.0, 10.0]; let mut it = xs.iter().scan(0, add); let mut i = 0; diff --git a/src/libstd/num/float.rs b/src/libstd/num/float.rs deleted file mode 100644 index 4f676545d4f06..0000000000000 --- a/src/libstd/num/float.rs +++ /dev/null @@ -1,1444 +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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Operations and constants for `float` - -// Even though this module exports everything defined in it, -// because it contains re-exports, we also have to explicitly -// export locally defined things. That's a bit annoying. - - -// export when m_float == c_double - - -// PORT this must match in width according to architecture - -#[allow(missing_doc)]; -#[allow(non_uppercase_statics)]; - -use default::Default; -use num::{Zero, One, strconv}; -use num::FPCategory; -use num; -use prelude::*; -use to_str; - -pub static NaN: float = 0.0/0.0; - -pub static infinity: float = 1.0/0.0; - -pub static neg_infinity: float = -1.0/0.0; - -/* Module: consts */ -pub mod consts { - // FIXME (requires Issue #1433 to fix): replace with mathematical - // constants from cmath. - /// Archimedes' constant - pub static pi: float = 3.14159265358979323846264338327950288; - - /// pi/2.0 - pub static frac_pi_2: float = 1.57079632679489661923132169163975144; - - /// pi/4.0 - pub static frac_pi_4: float = 0.785398163397448309615660845819875721; - - /// 1.0/pi - pub static frac_1_pi: float = 0.318309886183790671537767526745028724; - - /// 2.0/pi - pub static frac_2_pi: float = 0.636619772367581343075535053490057448; - - /// 2.0/sqrt(pi) - pub static frac_2_sqrtpi: float = 1.12837916709551257389615890312154517; - - /// sqrt(2.0) - pub static sqrt2: float = 1.41421356237309504880168872420969808; - - /// 1.0/sqrt(2.0) - pub static frac_1_sqrt2: float = 0.707106781186547524400844362104849039; - - /// Euler's number - pub static e: float = 2.71828182845904523536028747135266250; - - /// log2(e) - pub static log2_e: float = 1.44269504088896340735992468100189214; - - /// log10(e) - pub static log10_e: float = 0.434294481903251827651128918916605082; - - /// ln(2.0) - pub static ln_2: float = 0.693147180559945309417232121458176568; - - /// ln(10.0) - pub static ln_10: float = 2.30258509299404568401799145468436421; -} - -// -// Section: String Conversions -// - -/// -/// Converts a float to a string -/// -/// # Arguments -/// -/// * num - The float value -/// -#[inline] -pub fn to_str(num: float) -> ~str { - let (r, _) = strconv::float_to_str_common( - num, 10u, true, strconv::SignNeg, strconv::DigAll); - r -} - -/// -/// Converts a float to a string in hexadecimal format -/// -/// # Arguments -/// -/// * num - The float value -/// -#[inline] -pub fn to_str_hex(num: float) -> ~str { - let (r, _) = strconv::float_to_str_common( - num, 16u, true, strconv::SignNeg, strconv::DigAll); - r -} - -/// -/// Converts a float to a string in a given radix, and a flag indicating -/// whether it's a special value -/// -/// # Arguments -/// -/// * num - The float value -/// * radix - The base to use -/// -#[inline] -pub fn to_str_radix_special(num: float, radix: uint) -> (~str, bool) { - strconv::float_to_str_common(num, radix, true, - strconv::SignNeg, strconv::DigAll) -} - -/// -/// Converts a float to a string with exactly the number of -/// provided significant digits -/// -/// # Arguments -/// -/// * num - The float value -/// * digits - The number of significant digits -/// -#[inline] -pub fn to_str_exact(num: float, digits: uint) -> ~str { - let (r, _) = strconv::float_to_str_common( - num, 10u, true, strconv::SignNeg, strconv::DigExact(digits)); - r -} - -/// -/// Converts a float to a string with a maximum number of -/// significant digits -/// -/// # Arguments -/// -/// * num - The float value -/// * digits - The number of significant digits -/// -#[inline] -pub fn to_str_digits(num: float, digits: uint) -> ~str { - let (r, _) = strconv::float_to_str_common( - num, 10u, true, strconv::SignNeg, strconv::DigMax(digits)); - r -} - -impl to_str::ToStr for float { - #[inline] - fn to_str(&self) -> ~str { to_str_digits(*self, 8) } -} - -impl num::ToStrRadix for float { - /// Converts a float to a string in a given radix - /// - /// # Arguments - /// - /// * num - The float value - /// * radix - The base to use - /// - /// # Failure - /// - /// Fails if called on a special value like `inf`, `-inf` or `NaN` due to - /// possible misinterpretation of the result at higher bases. If those values - /// are expected, use `to_str_radix_special()` instead. - #[inline] - fn to_str_radix(&self, radix: uint) -> ~str { - let (r, special) = strconv::float_to_str_common( - *self, radix, true, strconv::SignNeg, strconv::DigAll); - if special { fail2!("number has a special value, \ - try to_str_radix_special() if those are expected") } - r - } -} - -/// -/// Convert a string in base 16 to a float. -/// Accepts a optional binary exponent. -/// -/// This function accepts strings such as -/// -/// * 'a4.fe' -/// * '+a4.fe', equivalent to 'a4.fe' -/// * '-a4.fe' -/// * '2b.aP128', or equivalently, '2b.ap128' -/// * '2b.aP-128' -/// * '.' (understood as 0) -/// * 'c.' -/// * '.c', or, equivalently, '0.c' -/// * '+inf', 'inf', '-inf', 'NaN' -/// -/// Leading and trailing whitespace represent an error. -/// -/// # Arguments -/// -/// * num - A string -/// -/// # Return value -/// -/// `none` if the string did not represent a valid number. Otherwise, -/// `Some(n)` where `n` is the floating-point number represented by `[num]`. -/// -#[inline] -pub fn from_str_hex(num: &str) -> Option { - strconv::from_str_common(num, 16u, true, true, true, - strconv::ExpBin, false, false) -} - -impl FromStr for float { - /// - /// Convert a string in base 10 to a float. - /// Accepts a optional decimal exponent. - /// - /// This function accepts strings such as - /// - /// * '3.14' - /// * '+3.14', equivalent to '3.14' - /// * '-3.14' - /// * '2.5E10', or equivalently, '2.5e10' - /// * '2.5E-10' - /// * '.' (understood as 0) - /// * '5.' - /// * '.5', or, equivalently, '0.5' - /// * '+inf', 'inf', '-inf', 'NaN' - /// - /// Leading and trailing whitespace represent an error. - /// - /// # Arguments - /// - /// * num - A string - /// - /// # Return value - /// - /// `none` if the string did not represent a valid number. Otherwise, - /// `Some(n)` where `n` is the floating-point number represented by `num`. - /// - #[inline] - fn from_str(val: &str) -> Option { - strconv::from_str_common(val, 10u, true, true, true, - strconv::ExpDec, false, false) - } -} - -impl num::FromStrRadix for float { - /// - /// Convert a string in an given base to a float. - /// - /// Due to possible conflicts, this function does **not** accept - /// the special values `inf`, `-inf`, `+inf` and `NaN`, **nor** - /// does it recognize exponents of any kind. - /// - /// Leading and trailing whitespace represent an error. - /// - /// # Arguments - /// - /// * num - A string - /// * radix - The base to use. Must lie in the range [2 .. 36] - /// - /// # Return value - /// - /// `none` if the string did not represent a valid number. Otherwise, - /// `Some(n)` where `n` is the floating-point number represented by `num`. - /// - #[inline] - fn from_str_radix(val: &str, radix: uint) -> Option { - strconv::from_str_common(val, radix, true, true, false, - strconv::ExpNone, false, false) - } -} - -// -// Section: Arithmetics -// - -/// -/// Compute the exponentiation of an integer by another integer as a float -/// -/// # Arguments -/// -/// * x - The base -/// * pow - The exponent -/// -/// # Return value -/// -/// `NaN` if both `x` and `pow` are `0u`, otherwise `x^pow` -/// -pub fn pow_with_uint(base: uint, pow: uint) -> float { - if base == 0u { - if pow == 0u { - return NaN as float; - } - return 0.; - } - let mut my_pow = pow; - let mut total = 1f; - let mut multiplier = base as float; - while (my_pow > 0u) { - if my_pow % 2u == 1u { - total = total * multiplier; - } - my_pow /= 2u; - multiplier *= multiplier; - } - return total; -} - -impl Num for float {} - -#[cfg(not(test))] -impl Eq for float { - #[inline] - fn eq(&self, other: &float) -> bool { (*self) == (*other) } -} - -#[cfg(not(test))] -impl ApproxEq for float { - #[inline] - fn approx_epsilon() -> float { 1.0e-6 } - - #[inline] - fn approx_eq(&self, other: &float) -> bool { - self.approx_eq_eps(other, &1.0e-6) - } - - #[inline] - fn approx_eq_eps(&self, other: &float, approx_epsilon: &float) -> bool { - (*self - *other).abs() < *approx_epsilon - } -} - -#[cfg(not(test))] -impl Ord for float { - #[inline] - fn lt(&self, other: &float) -> bool { (*self) < (*other) } - #[inline] - fn le(&self, other: &float) -> bool { (*self) <= (*other) } - #[inline] - fn ge(&self, other: &float) -> bool { (*self) >= (*other) } - #[inline] - fn gt(&self, other: &float) -> bool { (*self) > (*other) } -} - -impl Orderable for float { - /// Returns `NaN` if either of the numbers are `NaN`. - #[inline] - fn min(&self, other: &float) -> float { - (*self as f64).min(&(*other as f64)) as float - } - - /// Returns `NaN` if either of the numbers are `NaN`. - #[inline] - fn max(&self, other: &float) -> float { - (*self as f64).max(&(*other as f64)) as float - } - - /// Returns the number constrained within the range `mn <= self <= mx`. - /// If any of the numbers are `NaN` then `NaN` is returned. - #[inline] - fn clamp(&self, mn: &float, mx: &float) -> float { - (*self as f64).clamp(&(*mn as f64), &(*mx as f64)) as float - } -} - -impl Default for float { - #[inline] - fn default() -> float { 0.0 } -} - -impl Zero for float { - #[inline] - fn zero() -> float { 0.0 } - - /// Returns true if the number is equal to either `0.0` or `-0.0` - #[inline] - fn is_zero(&self) -> bool { *self == 0.0 || *self == -0.0 } -} - -impl One for float { - #[inline] - fn one() -> float { 1.0 } -} - -impl Round for float { - /// Round half-way cases toward `neg_infinity` - #[inline] - fn floor(&self) -> float { (*self as f64).floor() as float } - - /// Round half-way cases toward `infinity` - #[inline] - fn ceil(&self) -> float { (*self as f64).ceil() as float } - - /// Round half-way cases away from `0.0` - #[inline] - 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 { (*self as f64).trunc() as float } - - /// - /// The fractional part of the number, satisfying: - /// - /// ```rust - /// assert!(x == trunc(x) + fract(x)) - /// ``` - /// - #[inline] - fn fract(&self) -> float { *self - self.trunc() } -} - -impl Fractional for float { - /// The reciprocal (multiplicative inverse) of the number - #[inline] - fn recip(&self) -> float { 1.0 / *self } -} - -impl Algebraic for float { - #[inline] - fn pow(&self, n: &float) -> float { - (*self as f64).pow(&(*n as f64)) as float - } - - #[inline] - fn sqrt(&self) -> float { - (*self as f64).sqrt() as float - } - - #[inline] - fn rsqrt(&self) -> float { - (*self as f64).rsqrt() as float - } - - #[inline] - fn cbrt(&self) -> float { - (*self as f64).cbrt() as float - } - - #[inline] - fn hypot(&self, other: &float) -> float { - (*self as f64).hypot(&(*other as f64)) as float - } -} - -impl Trigonometric for float { - #[inline] - fn sin(&self) -> float { - (*self as f64).sin() as float - } - - #[inline] - fn cos(&self) -> float { - (*self as f64).cos() as float - } - - #[inline] - fn tan(&self) -> float { - (*self as f64).tan() as float - } - - #[inline] - fn asin(&self) -> float { - (*self as f64).asin() as float - } - - #[inline] - fn acos(&self) -> float { - (*self as f64).acos() as float - } - - #[inline] - fn atan(&self) -> float { - (*self as f64).atan() as float - } - - #[inline] - fn atan2(&self, other: &float) -> float { - (*self as f64).atan2(&(*other as f64)) as float - } - - /// Simultaneously computes the sine and cosine of the number - #[inline] - fn sin_cos(&self) -> (float, float) { - match (*self as f64).sin_cos() { - (s, c) => (s as float, c as float) - } - } -} - -impl Exponential for float { - /// Returns the exponential of the number - #[inline] - fn exp(&self) -> float { - (*self as f64).exp() as float - } - - /// Returns 2 raised to the power of the number - #[inline] - fn exp2(&self) -> float { - (*self as f64).exp2() as float - } - - /// Returns the natural logarithm of the number - #[inline] - fn ln(&self) -> float { - (*self as f64).ln() as float - } - - /// Returns the logarithm of the number with respect to an arbitrary base - #[inline] - fn log(&self, base: &float) -> float { - (*self as f64).log(&(*base as f64)) as float - } - - /// Returns the base 2 logarithm of the number - #[inline] - fn log2(&self) -> float { - (*self as f64).log2() as float - } - - /// Returns the base 10 logarithm of the number - #[inline] - fn log10(&self) -> float { - (*self as f64).log10() as float - } -} - -impl Hyperbolic for float { - #[inline] - fn sinh(&self) -> float { - (*self as f64).sinh() as float - } - - #[inline] - fn cosh(&self) -> float { - (*self as f64).cosh() as float - } - - #[inline] - fn tanh(&self) -> float { - (*self as f64).tanh() as float - } - - /// - /// Inverse hyperbolic sine - /// - /// # Returns - /// - /// - on success, the inverse hyperbolic sine of `self` will be returned - /// - `self` if `self` is `0.0`, `-0.0`, `infinity`, or `neg_infinity` - /// - `NaN` if `self` is `NaN` - /// - #[inline] - fn asinh(&self) -> float { - (*self as f64).asinh() as float - } - - /// - /// Inverse hyperbolic cosine - /// - /// # Returns - /// - /// - on success, the inverse hyperbolic cosine of `self` will be returned - /// - `infinity` if `self` is `infinity` - /// - `NaN` if `self` is `NaN` or `self < 1.0` (including `neg_infinity`) - /// - #[inline] - fn acosh(&self) -> float { - (*self as f64).acosh() as float - } - - /// - /// Inverse hyperbolic tangent - /// - /// # Returns - /// - /// - on success, the inverse hyperbolic tangent of `self` will be returned - /// - `self` if `self` is `0.0` or `-0.0` - /// - `infinity` if `self` is `1.0` - /// - `neg_infinity` if `self` is `-1.0` - /// - `NaN` if the `self` is `NaN` or outside the domain of `-1.0 <= self <= 1.0` - /// (including `infinity` and `neg_infinity`) - /// - #[inline] - fn atanh(&self) -> float { - (*self as f64).atanh() as float - } -} - -impl Real for float { - /// Archimedes' constant - #[inline] - fn pi() -> float { 3.14159265358979323846264338327950288 } - - /// 2.0 * pi - #[inline] - fn two_pi() -> float { 6.28318530717958647692528676655900576 } - - /// pi / 2.0 - #[inline] - fn frac_pi_2() -> float { 1.57079632679489661923132169163975144 } - - /// pi / 3.0 - #[inline] - fn frac_pi_3() -> float { 1.04719755119659774615421446109316763 } - - /// pi / 4.0 - #[inline] - fn frac_pi_4() -> float { 0.785398163397448309615660845819875721 } - - /// pi / 6.0 - #[inline] - fn frac_pi_6() -> float { 0.52359877559829887307710723054658381 } - - /// pi / 8.0 - #[inline] - fn frac_pi_8() -> float { 0.39269908169872415480783042290993786 } - - /// 1.0 / pi - #[inline] - fn frac_1_pi() -> float { 0.318309886183790671537767526745028724 } - - /// 2.0 / pi - #[inline] - fn frac_2_pi() -> float { 0.636619772367581343075535053490057448 } - - /// 2 .0/ sqrt(pi) - #[inline] - fn frac_2_sqrtpi() -> float { 1.12837916709551257389615890312154517 } - - /// sqrt(2.0) - #[inline] - fn sqrt2() -> float { 1.41421356237309504880168872420969808 } - - /// 1.0 / sqrt(2.0) - #[inline] - fn frac_1_sqrt2() -> float { 0.707106781186547524400844362104849039 } - - /// Euler's number - #[inline] - fn e() -> float { 2.71828182845904523536028747135266250 } - - /// log2(e) - #[inline] - fn log2_e() -> float { 1.44269504088896340735992468100189214 } - - /// log10(e) - #[inline] - fn log10_e() -> float { 0.434294481903251827651128918916605082 } - - /// ln(2.0) - #[inline] - fn ln_2() -> float { 0.693147180559945309417232121458176568 } - - /// ln(10.0) - #[inline] - fn ln_10() -> float { 2.30258509299404568401799145468436421 } - - /// Converts to degrees, assuming the number is in radians - #[inline] - fn to_degrees(&self) -> float { (*self as f64).to_degrees() as float } - - /// Converts to radians, assuming the number is in degrees - #[inline] - fn to_radians(&self) -> float { (*self as f64).to_radians() as float } -} - -impl RealExt for float { - #[inline] - fn lgamma(&self) -> (int, float) { - let (sign, value) = (*self as f64).lgamma(); - (sign, value as float) - } - - #[inline] - fn tgamma(&self) -> float { (*self as f64).tgamma() as float } - - #[inline] - fn j0(&self) -> float { (*self as f64).j0() as float } - - #[inline] - fn j1(&self) -> float { (*self as f64).j1() as float } - - #[inline] - fn jn(&self, n: int) -> float { (*self as f64).jn(n) as float } - - #[inline] - fn y0(&self) -> float { (*self as f64).y0() as float } - - #[inline] - fn y1(&self) -> float { (*self as f64).y1() as float } - - #[inline] - fn yn(&self, n: int) -> float { (*self as f64).yn(n) as float } -} - -#[cfg(not(test))] -impl Add for float { - #[inline] - fn add(&self, other: &float) -> float { *self + *other } -} - -#[cfg(not(test))] -impl Sub for float { - #[inline] - fn sub(&self, other: &float) -> float { *self - *other } -} - -#[cfg(not(test))] -impl Mul for float { - #[inline] - fn mul(&self, other: &float) -> float { *self * *other } -} - -#[cfg(not(test))] -impl Div for float { - #[inline] - fn div(&self, other: &float) -> float { *self / *other } -} - -#[cfg(not(test))] -impl Rem for float { - #[inline] - fn rem(&self, other: &float) -> float { *self % *other } -} -#[cfg(not(test))] -impl Neg for float { - #[inline] - 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 { (*self as f64).abs() as float } - - /// - /// The positive difference of two numbers. Returns `0.0` if the number is less than or - /// equal to `other`, otherwise the difference between`self` and `other` is returned. - /// - #[inline] - fn abs_sub(&self, other: &float) -> float { - (*self as f64).abs_sub(&(*other as f64)) as float - } - - /// - /// # Returns - /// - /// - `1.0` if the number is positive, `+0.0` or `infinity` - /// - `-1.0` if the number is negative, `-0.0` or `neg_infinity` - /// - `NaN` if the number is NaN - /// - #[inline] - fn signum(&self) -> float { - (*self as f64).signum() as float - } - - /// Returns `true` if the number is positive, including `+0.0` and `infinity` - #[inline] - fn is_positive(&self) -> bool { *self > 0.0 || (1.0 / *self) == infinity } - - /// Returns `true` if the number is negative, including `-0.0` and `neg_infinity` - #[inline] - fn is_negative(&self) -> bool { *self < 0.0 || (1.0 / *self) == neg_infinity } -} - -impl Bounded for float { - #[inline] - fn min_value() -> float { - let x: f64 = Bounded::min_value(); - x as float - } - - #[inline] - fn max_value() -> float { - let x: f64 = Bounded::max_value(); - x as float - } -} - -impl Primitive for float { - #[inline] - fn bits(_: Option) -> uint { - let bits: uint = Primitive::bits(Some(0f64)); - bits - } - - #[inline] - fn bytes(_: Option) -> uint { - let bytes: uint = Primitive::bytes(Some(0f64)); - bytes - } -} - -impl Float for float { - #[inline] - fn nan() -> float { - let value: f64 = Float::nan(); - value as float - } - - #[inline] - fn infinity() -> float { - let value: f64 = Float::infinity(); - value as float - } - - #[inline] - fn neg_infinity() -> float { - let value: f64 = Float::neg_infinity(); - value as float - } - - #[inline] - fn neg_zero() -> float { - let value: f64 = Float::neg_zero(); - value as float - } - - /// Returns `true` if the number is NaN - #[inline] - fn is_nan(&self) -> bool { (*self as f64).is_nan() } - - /// Returns `true` if the number is infinite - #[inline] - fn is_infinite(&self) -> bool { (*self as f64).is_infinite() } - - /// Returns `true` if the number is neither infinite or NaN - #[inline] - fn is_finite(&self) -> bool { (*self as f64).is_finite() } - - /// Returns `true` if the number is neither zero, infinite, subnormal or NaN - #[inline] - fn is_normal(&self) -> bool { (*self as f64).is_normal() } - - /// Returns the floating point category of the number. If only one property is going to - /// be tested, it is generally faster to use the specific predicate instead. - #[inline] - fn classify(&self) -> FPCategory { (*self as f64).classify() } - - #[inline] - fn mantissa_digits(_: Option) -> uint { - Float::mantissa_digits(Some(0f64)) - } - - #[inline] - fn digits(_: Option) -> uint { - Float::digits(Some(0f64)) - } - - #[inline] - fn epsilon() -> float { - let value: f64 = Float::epsilon(); - value as float - } - - #[inline] - fn min_exp(_: Option) -> int { - Float::min_exp(Some(0f64)) - } - - #[inline] - fn max_exp(_: Option) -> int { - Float::max_exp(Some(0f64)) - } - - #[inline] - fn min_10_exp(_: Option) -> int { - Float::min_10_exp(Some(0f64)) - } - - #[inline] - fn max_10_exp(_: Option) -> int { - Float::max_10_exp(Some(0f64)) - } - - /// Constructs a floating point number by multiplying `x` by 2 raised to the power of `exp` - #[inline] - fn ldexp(x: float, exp: int) -> float { - let value: f64 = Float::ldexp(x as f64, exp); - value as float - } - - /// - /// Breaks the number into a normalized fraction and a base-2 exponent, satisfying: - /// - /// - `self = x * pow(2, exp)` - /// - `0.5 <= abs(x) < 1.0` - /// - #[inline] - fn frexp(&self) -> (float, int) { - match (*self as f64).frexp() { - (x, exp) => (x as float, exp) - } - } - - /// - /// Returns the exponential of the number, minus `1`, in a way that is accurate - /// even if the number is close to zero - /// - #[inline] - fn exp_m1(&self) -> float { - (*self as f64).exp_m1() as float - } - - /// - /// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more accurately - /// than if the operations were performed separately - /// - #[inline] - fn ln_1p(&self) -> float { - (*self as f64).ln_1p() as float - } - - /// - /// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. This - /// produces a more accurate result with better performance than a separate multiplication - /// operation followed by an add. - /// - #[inline] - fn mul_add(&self, a: float, b: float) -> 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 { - (*self as f64).next_after(other as f64) as float - } -} - -#[cfg(test)] -mod tests { - use prelude::*; - use super::*; - - use num::*; - use num; - use sys; - - #[test] - fn test_num() { - num::test_num(10f, 2f); - } - - #[test] - fn test_min() { - assert_eq!(1f.min(&2f), 1f); - assert_eq!(2f.min(&1f), 1f); - } - - #[test] - fn test_max() { - assert_eq!(1f.max(&2f), 2f); - assert_eq!(2f.max(&1f), 2f); - } - - #[test] - fn test_clamp() { - assert_eq!(1f.clamp(&2f, &4f), 2f); - assert_eq!(8f.clamp(&2f, &4f), 4f); - assert_eq!(3f.clamp(&2f, &4f), 3f); - let nan: float = Float::nan(); - assert!(3f.clamp(&nan, &4f).is_nan()); - assert!(3f.clamp(&2f, &nan).is_nan()); - assert!(nan.clamp(&2f, &4f).is_nan()); - } - - #[test] - fn test_floor() { - assert_approx_eq!(1.0f.floor(), 1.0f); - assert_approx_eq!(1.3f.floor(), 1.0f); - assert_approx_eq!(1.5f.floor(), 1.0f); - assert_approx_eq!(1.7f.floor(), 1.0f); - assert_approx_eq!(0.0f.floor(), 0.0f); - assert_approx_eq!((-0.0f).floor(), -0.0f); - assert_approx_eq!((-1.0f).floor(), -1.0f); - assert_approx_eq!((-1.3f).floor(), -2.0f); - assert_approx_eq!((-1.5f).floor(), -2.0f); - assert_approx_eq!((-1.7f).floor(), -2.0f); - } - - #[test] - fn test_ceil() { - assert_approx_eq!(1.0f.ceil(), 1.0f); - assert_approx_eq!(1.3f.ceil(), 2.0f); - assert_approx_eq!(1.5f.ceil(), 2.0f); - assert_approx_eq!(1.7f.ceil(), 2.0f); - assert_approx_eq!(0.0f.ceil(), 0.0f); - assert_approx_eq!((-0.0f).ceil(), -0.0f); - assert_approx_eq!((-1.0f).ceil(), -1.0f); - assert_approx_eq!((-1.3f).ceil(), -1.0f); - assert_approx_eq!((-1.5f).ceil(), -1.0f); - assert_approx_eq!((-1.7f).ceil(), -1.0f); - } - - #[test] - fn test_round() { - assert_approx_eq!(1.0f.round(), 1.0f); - assert_approx_eq!(1.3f.round(), 1.0f); - assert_approx_eq!(1.5f.round(), 2.0f); - assert_approx_eq!(1.7f.round(), 2.0f); - assert_approx_eq!(0.0f.round(), 0.0f); - assert_approx_eq!((-0.0f).round(), -0.0f); - assert_approx_eq!((-1.0f).round(), -1.0f); - assert_approx_eq!((-1.3f).round(), -1.0f); - assert_approx_eq!((-1.5f).round(), -2.0f); - assert_approx_eq!((-1.7f).round(), -2.0f); - } - - #[test] - fn test_trunc() { - assert_approx_eq!(1.0f.trunc(), 1.0f); - assert_approx_eq!(1.3f.trunc(), 1.0f); - assert_approx_eq!(1.5f.trunc(), 1.0f); - assert_approx_eq!(1.7f.trunc(), 1.0f); - assert_approx_eq!(0.0f.trunc(), 0.0f); - assert_approx_eq!((-0.0f).trunc(), -0.0f); - assert_approx_eq!((-1.0f).trunc(), -1.0f); - assert_approx_eq!((-1.3f).trunc(), -1.0f); - assert_approx_eq!((-1.5f).trunc(), -1.0f); - assert_approx_eq!((-1.7f).trunc(), -1.0f); - } - - #[test] - fn test_fract() { - assert_approx_eq!(1.0f.fract(), 0.0f); - assert_approx_eq!(1.3f.fract(), 0.3f); - assert_approx_eq!(1.5f.fract(), 0.5f); - assert_approx_eq!(1.7f.fract(), 0.7f); - assert_approx_eq!(0.0f.fract(), 0.0f); - assert_approx_eq!((-0.0f).fract(), -0.0f); - assert_approx_eq!((-1.0f).fract(), -0.0f); - assert_approx_eq!((-1.3f).fract(), -0.3f); - assert_approx_eq!((-1.5f).fract(), -0.5f); - assert_approx_eq!((-1.7f).fract(), -0.7f); - } - - #[test] - fn test_asinh() { - assert_eq!(0.0f.asinh(), 0.0f); - assert_eq!((-0.0f).asinh(), -0.0f); - - let inf: float = Float::infinity(); - let neg_inf: float = Float::neg_infinity(); - let nan: float = Float::nan(); - assert_eq!(inf.asinh(), inf); - assert_eq!(neg_inf.asinh(), neg_inf); - assert!(nan.asinh().is_nan()); - assert_approx_eq!(2.0f.asinh(), 1.443635475178810342493276740273105f); - assert_approx_eq!((-2.0f).asinh(), -1.443635475178810342493276740273105f); - } - - #[test] - fn test_acosh() { - assert_eq!(1.0f.acosh(), 0.0f); - assert!(0.999f.acosh().is_nan()); - - let inf: float = Float::infinity(); - let neg_inf: float = Float::neg_infinity(); - let nan: float = Float::nan(); - assert_eq!(inf.acosh(), inf); - assert!(neg_inf.acosh().is_nan()); - assert!(nan.acosh().is_nan()); - assert_approx_eq!(2.0f.acosh(), 1.31695789692481670862504634730796844f); - assert_approx_eq!(3.0f.acosh(), 1.76274717403908605046521864995958461f); - } - - #[test] - fn test_atanh() { - assert_eq!(0.0f.atanh(), 0.0f); - assert_eq!((-0.0f).atanh(), -0.0f); - - let inf: float = Float::infinity(); - let neg_inf: float = Float::neg_infinity(); - let inf64: f64 = Float::infinity(); - let neg_inf64: f64 = Float::neg_infinity(); - let nan: float = Float::nan(); - assert_eq!(1.0f.atanh(), inf); - assert_eq!((-1.0f).atanh(), neg_inf); - assert!(2f64.atanh().atanh().is_nan()); - assert!((-2f64).atanh().atanh().is_nan()); - assert!(inf64.atanh().is_nan()); - assert!(neg_inf64.atanh().is_nan()); - assert!(nan.atanh().is_nan()); - assert_approx_eq!(0.5f.atanh(), 0.54930614433405484569762261846126285f); - assert_approx_eq!((-0.5f).atanh(), -0.54930614433405484569762261846126285f); - } - - #[test] - fn test_real_consts() { - let pi: float = Real::pi(); - let two_pi: float = Real::two_pi(); - let frac_pi_2: float = Real::frac_pi_2(); - let frac_pi_3: float = Real::frac_pi_3(); - let frac_pi_4: float = Real::frac_pi_4(); - let frac_pi_6: float = Real::frac_pi_6(); - let frac_pi_8: float = Real::frac_pi_8(); - let frac_1_pi: float = Real::frac_1_pi(); - let frac_2_pi: float = Real::frac_2_pi(); - let frac_2_sqrtpi: float = Real::frac_2_sqrtpi(); - let sqrt2: float = Real::sqrt2(); - let frac_1_sqrt2: float = Real::frac_1_sqrt2(); - let e: float = Real::e(); - let log2_e: float = Real::log2_e(); - let log10_e: float = Real::log10_e(); - let ln_2: float = Real::ln_2(); - let ln_10: float = Real::ln_10(); - - assert_approx_eq!(two_pi, 2f * pi); - assert_approx_eq!(frac_pi_2, pi / 2f); - assert_approx_eq!(frac_pi_3, pi / 3f); - assert_approx_eq!(frac_pi_4, pi / 4f); - assert_approx_eq!(frac_pi_6, pi / 6f); - assert_approx_eq!(frac_pi_8, pi / 8f); - assert_approx_eq!(frac_1_pi, 1f / pi); - assert_approx_eq!(frac_2_pi, 2f / pi); - assert_approx_eq!(frac_2_sqrtpi, 2f / pi.sqrt()); - assert_approx_eq!(sqrt2, 2f.sqrt()); - assert_approx_eq!(frac_1_sqrt2, 1f / 2f.sqrt()); - assert_approx_eq!(log2_e, e.log2()); - assert_approx_eq!(log10_e, e.log10()); - assert_approx_eq!(ln_2, 2f.ln()); - assert_approx_eq!(ln_10, 10f.ln()); - } - - #[test] - fn test_abs() { - assert_eq!(infinity.abs(), infinity); - assert_eq!(1f.abs(), 1f); - assert_eq!(0f.abs(), 0f); - assert_eq!((-0f).abs(), 0f); - assert_eq!((-1f).abs(), 1f); - assert_eq!(neg_infinity.abs(), infinity); - assert_eq!((1f/neg_infinity).abs(), 0f); - assert!(NaN.abs().is_nan()); - } - - #[test] - fn test_abs_sub() { - assert_eq!((-1f).abs_sub(&1f), 0f); - assert_eq!(1f.abs_sub(&1f), 0f); - assert_eq!(1f.abs_sub(&0f), 1f); - assert_eq!(1f.abs_sub(&-1f), 2f); - assert_eq!(neg_infinity.abs_sub(&0f), 0f); - assert_eq!(infinity.abs_sub(&1f), infinity); - assert_eq!(0f.abs_sub(&neg_infinity), infinity); - assert_eq!(0f.abs_sub(&infinity), 0f); - } - - #[test] #[ignore(cfg(windows))] // FIXME #8663 - fn test_abs_sub_nowin() { - assert!(NaN.abs_sub(&-1f).is_nan()); - assert!(1f.abs_sub(&NaN).is_nan()); - } - - #[test] - fn test_signum() { - assert_eq!(infinity.signum(), 1f); - assert_eq!(1f.signum(), 1f); - assert_eq!(0f.signum(), 1f); - assert_eq!((-0f).signum(), -1f); - assert_eq!((-1f).signum(), -1f); - assert_eq!(neg_infinity.signum(), -1f); - assert_eq!((1f/neg_infinity).signum(), -1f); - assert!(NaN.signum().is_nan()); - } - - #[test] - fn test_is_positive() { - assert!(infinity.is_positive()); - assert!(1f.is_positive()); - assert!(0f.is_positive()); - assert!(!(-0f).is_positive()); - assert!(!(-1f).is_positive()); - assert!(!neg_infinity.is_positive()); - assert!(!(1f/neg_infinity).is_positive()); - assert!(!NaN.is_positive()); - } - - #[test] - fn test_is_negative() { - assert!(!infinity.is_negative()); - assert!(!1f.is_negative()); - assert!(!0f.is_negative()); - assert!((-0f).is_negative()); - assert!((-1f).is_negative()); - assert!(neg_infinity.is_negative()); - assert!((1f/neg_infinity).is_negative()); - assert!(!NaN.is_negative()); - } - - #[test] - fn test_approx_eq() { - assert!(1.0f.approx_eq(&1f)); - assert!(0.9999999f.approx_eq(&1f)); - assert!(1.000001f.approx_eq_eps(&1f, &1.0e-5)); - assert!(1.0000001f.approx_eq_eps(&1f, &1.0e-6)); - assert!(!1.0000001f.approx_eq_eps(&1f, &1.0e-7)); - } - - #[test] - fn test_primitive() { - let none: Option = None; - assert_eq!(Primitive::bits(none), sys::size_of::() * 8); - assert_eq!(Primitive::bytes(none), sys::size_of::()); - } - - #[test] - fn test_is_normal() { - let nan: float = Float::nan(); - let inf: float = Float::infinity(); - let neg_inf: float = Float::neg_infinity(); - let zero: float = Zero::zero(); - let neg_zero: float = Float::neg_zero(); - assert!(!nan.is_normal()); - assert!(!inf.is_normal()); - assert!(!neg_inf.is_normal()); - assert!(!zero.is_normal()); - assert!(!neg_zero.is_normal()); - assert!(1f.is_normal()); - assert!(1e-307f.is_normal()); - assert!(!1e-308f.is_normal()); - } - - #[test] - fn test_classify() { - let nan: float = Float::nan(); - let inf: float = Float::infinity(); - let neg_inf: float = Float::neg_infinity(); - let zero: float = Zero::zero(); - let neg_zero: float = Float::neg_zero(); - assert_eq!(nan.classify(), FPNaN); - assert_eq!(inf.classify(), FPInfinite); - assert_eq!(neg_inf.classify(), FPInfinite); - assert_eq!(zero.classify(), FPZero); - assert_eq!(neg_zero.classify(), FPZero); - assert_eq!(1f.classify(), FPNormal); - assert_eq!(1e-307f.classify(), FPNormal); - assert_eq!(1e-308f.classify(), FPSubnormal); - } - - #[test] - fn test_ldexp() { - // We have to use from_str until base-2 exponents - // are supported in floating-point literals - let f1: float = from_str_hex("1p-123").unwrap(); - let f2: float = from_str_hex("1p-111").unwrap(); - assert_eq!(Float::ldexp(1f, -123), f1); - assert_eq!(Float::ldexp(1f, -111), f2); - - assert_eq!(Float::ldexp(0f, -123), 0f); - assert_eq!(Float::ldexp(-0f, -123), -0f); - - let inf: float = Float::infinity(); - let neg_inf: float = Float::neg_infinity(); - let nan: float = Float::nan(); - assert_eq!(Float::ldexp(inf, -123), inf); - assert_eq!(Float::ldexp(neg_inf, -123), neg_inf); - assert!(Float::ldexp(nan, -123).is_nan()); - } - - #[test] - fn test_frexp() { - // We have to use from_str until base-2 exponents - // are supported in floating-point literals - let f1: float = from_str_hex("1p-123").unwrap(); - let f2: float = from_str_hex("1p-111").unwrap(); - let (x1, exp1) = f1.frexp(); - let (x2, exp2) = f2.frexp(); - assert_eq!((x1, exp1), (0.5f, -122)); - assert_eq!((x2, exp2), (0.5f, -110)); - assert_eq!(Float::ldexp(x1, exp1), f1); - assert_eq!(Float::ldexp(x2, exp2), f2); - - assert_eq!(0f.frexp(), (0f, 0)); - assert_eq!((-0f).frexp(), (-0f, 0)); - } - - #[test] #[ignore(cfg(windows))] // FIXME #8755 - fn test_frexp_nowin() { - let inf: float = Float::infinity(); - let neg_inf: float = Float::neg_infinity(); - let nan: float = Float::nan(); - assert_eq!(match inf.frexp() { (x, _) => x }, inf); - assert_eq!(match neg_inf.frexp() { (x, _) => x }, neg_inf); - assert!(match nan.frexp() { (x, _) => x.is_nan() }) - } - - #[test] - pub fn test_to_str_exact_do_decimal() { - let s = to_str_exact(5.0, 4u); - assert_eq!(s, ~"5.0000"); - } - - #[test] - pub fn test_from_str() { - assert_eq!(from_str::("3"), Some(3.)); - assert_eq!(from_str::("3.14"), Some(3.14)); - assert_eq!(from_str::("+3.14"), Some(3.14)); - assert_eq!(from_str::("-3.14"), Some(-3.14)); - assert_eq!(from_str::("2.5E10"), Some(25000000000.)); - assert_eq!(from_str::("2.5e10"), Some(25000000000.)); - assert_eq!(from_str::("25000000000.E-10"), Some(2.5)); - assert_eq!(from_str::("."), Some(0.)); - assert_eq!(from_str::(".e1"), Some(0.)); - assert_eq!(from_str::(".e-1"), Some(0.)); - assert_eq!(from_str::("5."), Some(5.)); - assert_eq!(from_str::(".5"), Some(0.5)); - assert_eq!(from_str::("0.5"), Some(0.5)); - assert_eq!(from_str::("-.5"), Some(-0.5)); - assert_eq!(from_str::("-5"), Some(-5.)); - assert_eq!(from_str::("inf"), Some(infinity)); - assert_eq!(from_str::("+inf"), Some(infinity)); - assert_eq!(from_str::("-inf"), Some(neg_infinity)); - // note: NaN != NaN, hence this slightly complex test - match from_str::("NaN") { - Some(f) => assert!(f.is_nan()), - None => fail2!() - } - // note: -0 == 0, hence these slightly more complex tests - match from_str::("-0") { - Some(v) if v.is_zero() => assert!(v.is_negative()), - _ => fail2!() - } - match from_str::("0") { - Some(v) if v.is_zero() => assert!(v.is_positive()), - _ => fail2!() - } - - assert!(from_str::("").is_none()); - assert!(from_str::("x").is_none()); - assert!(from_str::(" ").is_none()); - assert!(from_str::(" ").is_none()); - assert!(from_str::("e").is_none()); - assert!(from_str::("E").is_none()); - assert!(from_str::("E1").is_none()); - assert!(from_str::("1e1e1").is_none()); - assert!(from_str::("1e1.1").is_none()); - assert!(from_str::("1e1-1").is_none()); - } - - #[test] - pub fn test_from_str_hex() { - assert_eq!(from_str_hex("a4"), Some(164.)); - assert_eq!(from_str_hex("a4.fe"), Some(164.9921875)); - assert_eq!(from_str_hex("-a4.fe"), Some(-164.9921875)); - assert_eq!(from_str_hex("+a4.fe"), Some(164.9921875)); - assert_eq!(from_str_hex("ff0P4"), Some(0xff00 as float)); - assert_eq!(from_str_hex("ff0p4"), Some(0xff00 as float)); - assert_eq!(from_str_hex("ff0p-4"), Some(0xff as float)); - assert_eq!(from_str_hex("."), Some(0.)); - assert_eq!(from_str_hex(".p1"), Some(0.)); - assert_eq!(from_str_hex(".p-1"), Some(0.)); - assert_eq!(from_str_hex("f."), Some(15.)); - assert_eq!(from_str_hex(".f"), Some(0.9375)); - assert_eq!(from_str_hex("0.f"), Some(0.9375)); - assert_eq!(from_str_hex("-.f"), Some(-0.9375)); - assert_eq!(from_str_hex("-f"), Some(-15.)); - assert_eq!(from_str_hex("inf"), Some(infinity)); - assert_eq!(from_str_hex("+inf"), Some(infinity)); - assert_eq!(from_str_hex("-inf"), Some(neg_infinity)); - // note: NaN != NaN, hence this slightly complex test - match from_str_hex("NaN") { - Some(f) => assert!(f.is_nan()), - None => fail2!() - } - // note: -0 == 0, hence these slightly more complex tests - match from_str_hex("-0") { - Some(v) if v.is_zero() => assert!(v.is_negative()), - _ => fail2!() - } - match from_str_hex("0") { - Some(v) if v.is_zero() => assert!(v.is_positive()), - _ => fail2!() - } - assert_eq!(from_str_hex("e"), Some(14.)); - assert_eq!(from_str_hex("E"), Some(14.)); - assert_eq!(from_str_hex("E1"), Some(225.)); - assert_eq!(from_str_hex("1e1e1"), Some(123361.)); - assert_eq!(from_str_hex("1e1.1"), Some(481.0625)); - - assert!(from_str_hex("").is_none()); - assert!(from_str_hex("x").is_none()); - assert!(from_str_hex(" ").is_none()); - assert!(from_str_hex(" ").is_none()); - assert!(from_str_hex("p").is_none()); - assert!(from_str_hex("P").is_none()); - assert!(from_str_hex("P1").is_none()); - assert!(from_str_hex("1p1p1").is_none()); - assert!(from_str_hex("1p1.1").is_none()); - assert!(from_str_hex("1p1-1").is_none()); - } - - #[test] - pub fn test_to_str_hex() { - assert_eq!(to_str_hex(164.), ~"a4"); - assert_eq!(to_str_hex(164.9921875), ~"a4.fe"); - assert_eq!(to_str_hex(-164.9921875), ~"-a4.fe"); - assert_eq!(to_str_hex(0xff00 as float), ~"ff00"); - assert_eq!(to_str_hex(-(0xff00 as float)), ~"-ff00"); - assert_eq!(to_str_hex(0.), ~"0"); - assert_eq!(to_str_hex(15.), ~"f"); - assert_eq!(to_str_hex(-15.), ~"-f"); - assert_eq!(to_str_hex(0.9375), ~"0.f"); - assert_eq!(to_str_hex(-0.9375), ~"-0.f"); - assert_eq!(to_str_hex(infinity), ~"inf"); - assert_eq!(to_str_hex(neg_infinity), ~"-inf"); - assert_eq!(to_str_hex(NaN), ~"NaN"); - assert_eq!(to_str_hex(0.), ~"0"); - assert_eq!(to_str_hex(-0.), ~"-0"); - } - - #[test] - pub fn test_to_str_radix() { - assert_eq!(36.0f.to_str_radix(36u), ~"10"); - assert_eq!(8.125f.to_str_radix(2u), ~"1000.001"); - } - - #[test] - pub fn test_from_str_radix() { - assert_eq!(from_str_radix("10", 36u), Some(36.)); - assert_eq!(from_str_radix("1000.001", 2u), Some(8.125)); - } - - #[test] - pub fn test_to_str_inf() { - assert_eq!(to_str_digits(infinity, 10u), ~"inf"); - assert_eq!(to_str_digits(-infinity, 10u), ~"-inf"); - } -} diff --git a/src/libstd/num/num.rs b/src/libstd/num/num.rs index a60bf2f33a99d..95b1057dfd080 100644 --- a/src/libstd/num/num.rs +++ b/src/libstd/num/num.rs @@ -385,7 +385,6 @@ pub trait NumCast { fn to_f32(&self) -> f32; fn to_f64(&self) -> f64; - fn to_float(&self) -> float; } macro_rules! impl_num_cast( @@ -412,7 +411,6 @@ macro_rules! impl_num_cast( #[inline] fn to_f32(&self) -> f32 { *self as f32 } #[inline] fn to_f64(&self) -> f64 { *self as f64 } - #[inline] fn to_float(&self) -> float { *self as float } } ) ) @@ -429,7 +427,6 @@ impl_num_cast!(i64, to_i64) impl_num_cast!(int, to_int) impl_num_cast!(f32, to_f32) impl_num_cast!(f64, to_f64) -impl_num_cast!(float, to_float) pub trait ToStrRadix { fn to_str_radix(&self, radix: uint) -> ~str; @@ -579,7 +576,6 @@ mod tests { assert_eq!(20i16, _20.to_i16()); assert_eq!(20i32, _20.to_i32()); assert_eq!(20i64, _20.to_i64()); - assert_eq!(20f, _20.to_float()); assert_eq!(20f32, _20.to_f32()); assert_eq!(20f64, _20.to_f64()); @@ -593,7 +589,6 @@ mod tests { assert_eq!(_20, NumCast::from(20i16)); assert_eq!(_20, NumCast::from(20i32)); assert_eq!(_20, NumCast::from(20i64)); - assert_eq!(_20, NumCast::from(20f)); assert_eq!(_20, NumCast::from(20f32)); assert_eq!(_20, NumCast::from(20f64)); @@ -607,7 +602,6 @@ mod tests { assert_eq!(_20, cast(20i16)); assert_eq!(_20, cast(20i32)); assert_eq!(_20, cast(20i64)); - assert_eq!(_20, cast(20f)); assert_eq!(_20, cast(20f32)); assert_eq!(_20, cast(20f64)); }) @@ -625,7 +619,6 @@ mod tests { #[test] fn test_int_cast() { test_cast_20!(20i) } #[test] fn test_f32_cast() { test_cast_20!(20f32) } #[test] fn test_f64_cast() { test_cast_20!(20f64) } - #[test] fn test_float_cast() { test_cast_20!(20f) } #[test] fn test_saturating_add_uint() { diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 19e6a2dd0ef6b..c45d77dad9d46 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -83,7 +83,6 @@ macro_rules! impl_NumStrConv_Integer (($t:ty) => ( // FIXME: #4955 // Replace by two generic impls for traits 'Integral' and 'Floating' -impl_NumStrConv_Floating!(float) impl_NumStrConv_Floating!(f32) impl_NumStrConv_Floating!(f64) @@ -735,8 +734,8 @@ mod test { mod bench { use extra::test::BenchHarness; use rand::{XorShiftRng, Rng}; - use float; use to_str::ToStr; + use f64; #[bench] fn uint_to_str_rand(bh: &mut BenchHarness) { @@ -750,7 +749,7 @@ mod bench { fn float_to_str_rand(bh: &mut BenchHarness) { let mut rng = XorShiftRng::new(); do bh.iter { - float::to_str(rng.gen()); + f64::to_str(rng.gen()); } } } diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index cc0e843b89650..5a7708b7fb224 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -14,7 +14,7 @@ Random number generation. The key functions are `random()` and `Rng::gen()`. These are polymorphic and so can be used to generate any type that implements `Rand`. Type inference means that often a simple call to `rand::random()` or `rng.gen()` will -suffice, but sometimes an annotation is required, e.g. `rand::random::()`. +suffice, but sometimes an annotation is required, e.g. `rand::random::()`. See the `distributions` submodule for sampling random numbers from distributions like normal and exponential. @@ -145,13 +145,6 @@ impl Rand for u64 { } } -impl Rand for float { - #[inline] - fn rand(rng: &mut R) -> float { - rng.gen::() as float - } -} - impl Rand for f32 { #[inline] fn rand(rng: &mut R) -> f32 { @@ -271,7 +264,7 @@ pub trait Rng { /// let rng = rand::task_rng(); /// let x: uint = rng.gen(); /// println!("{}", x); - /// println!("{:?}", rng.gen::<(float, bool)>()); + /// println!("{:?}", rng.gen::<(f64, bool)>()); /// } /// ``` #[inline(always)] @@ -290,7 +283,7 @@ pub trait Rng { /// let rng = rand::task_rng(); /// let x: ~[uint] = rng.gen_vec(10); /// println!("{:?}", x); - /// println!("{:?}", rng.gen_vec::<(float, bool)>(5)); + /// println!("{:?}", rng.gen_vec::<(f64, bool)>(5)); /// } /// ``` fn gen_vec(&mut self, len: uint) -> ~[T] { @@ -936,10 +929,10 @@ mod test { } #[test] - fn test_gen_float() { + fn test_gen_f64() { let mut r = rng(); - let a = r.gen::(); - let b = r.gen::(); + let a = r.gen::(); + let b = r.gen::(); debug2!("{:?}", (a, b)); } @@ -1049,7 +1042,7 @@ mod test { let _many : ((), (~uint, @int, ~Option<~(@u32, ~(@bool,))>), (u8, i8, u16, i16, u32, i32, u64, i64), - (f32, (f64, (float,)))) = random(); + (f32, (f64, (f64,)))) = random(); } #[test] diff --git a/src/libstd/reflect.rs b/src/libstd/reflect.rs index 833a9f5ed8256..00b2b308c6f9a 100644 --- a/src/libstd/reflect.rs +++ b/src/libstd/reflect.rs @@ -166,6 +166,7 @@ impl TyVisitor for MovePtrAdaptor { true } + #[cfg(stage0)] fn visit_float(&mut self) -> bool { self.align_to::(); if ! self.inner.visit_float() { return false; } diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index e9d1accbd4795..f5a481785ddb9 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -78,13 +78,6 @@ int_repr!(u16, "u16") int_repr!(u32, "u32") int_repr!(u64, "u64") -impl Repr for float { - fn write_repr(&self, writer: &mut io::Writer) { - let s = self.to_str(); - writer.write(s.as_bytes()); - } -} - macro_rules! num_repr(($ty:ident, $suffix:expr) => (impl Repr for $ty { fn write_repr(&self, writer: &mut io::Writer) { let s = self.to_str(); @@ -278,7 +271,8 @@ impl<'self> TyVisitor for ReprVisitor<'self> { fn visit_u32(&mut self) -> bool { self.write::() } fn visit_u64(&mut self) -> bool { self.write::() } - fn visit_float(&mut self) -> bool { self.write::() } + #[cfg(stage0)] + fn visit_float(&mut self) -> bool { self.write::() } fn visit_f32(&mut self) -> bool { self.write::() } fn visit_f64(&mut self) -> bool { self.write::() } @@ -632,7 +626,7 @@ pub fn write_repr(writer: &mut io::Writer, object: &T) { } #[cfg(test)] -struct P {a: int, b: float} +struct P {a: int, b: f64} #[test] fn test_repr() { @@ -653,7 +647,7 @@ fn test_repr() { exact_test(&10, "10"); exact_test(&true, "true"); exact_test(&false, "false"); - exact_test(&1.234, "1.234"); + exact_test(&1.234, "1.234f64"); exact_test(&(&"hello"), "\"hello\""); exact_test(&(@"hello"), "@\"hello\""); exact_test(&(~"he\u10f3llo"), "~\"he\\u10f3llo\""); @@ -682,11 +676,11 @@ fn test_repr() { exact_test(&(&["hi", "there"]), "&[\"hi\", \"there\"]"); exact_test(&(P{a:10, b:1.234}), - "repr::P{a: 10, b: 1.234}"); + "repr::P{a: 10, b: 1.234f64}"); exact_test(&(@P{a:10, b:1.234}), - "@repr::P{a: 10, b: 1.234}"); + "@repr::P{a: 10, b: 1.234f64}"); exact_test(&(~P{a:10, b:1.234}), - "~repr::P{a: 10, b: 1.234}"); + "~repr::P{a: 10, b: 1.234f64}"); exact_test(&(10u8, ~"hello"), "(10u8, ~\"hello\")"); exact_test(&(10u16, ~"hello"), diff --git a/src/libstd/std.rs b/src/libstd/std.rs index b5e6a50e0f03d..ece623fab247e 100644 --- a/src/libstd/std.rs +++ b/src/libstd/std.rs @@ -109,7 +109,6 @@ pub mod prelude; #[path = "num/u32.rs"] pub mod u32; #[path = "num/u64.rs"] pub mod u64; -#[path = "num/float.rs"] pub mod float; #[path = "num/f32.rs"] pub mod f32; #[path = "num/f64.rs"] pub mod f64; diff --git a/src/libstd/to_bytes.rs b/src/libstd/to_bytes.rs index f47468e1ef8ca..4d5da19dafda9 100644 --- a/src/libstd/to_bytes.rs +++ b/src/libstd/to_bytes.rs @@ -198,13 +198,6 @@ impl IterBytes for int { } } -impl IterBytes for float { - #[inline] - fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { - (*self as f64).iter_bytes(lsb0, f) - } -} - impl IterBytes for f32 { #[inline] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { diff --git a/src/libstd/unstable/extfmt.rs b/src/libstd/unstable/extfmt.rs index b224c22df20a6..0131f2c603cda 100644 --- a/src/libstd/unstable/extfmt.rs +++ b/src/libstd/unstable/extfmt.rs @@ -480,7 +480,7 @@ pub mod ct { #[doc(hidden)] #[allow(non_uppercase_statics)] pub mod rt { - use float; + use f64; use str; use sys; use num; @@ -563,10 +563,10 @@ pub mod rt { }; pad(cv, unpadded, None, PadNozero, buf); } - pub fn conv_float(cv: Conv, f: float, buf: &mut ~str) { + pub fn conv_float(cv: Conv, f: f64, buf: &mut ~str) { let (to_str, digits) = match cv.precision { - CountIs(c) => (float::to_str_exact, c as uint), - CountImplied => (float::to_str_digits, 6u) + CountIs(c) => (f64::to_str_exact, c as uint), + CountImplied => (f64::to_str_digits, 6u) }; let s = to_str(f, digits); let head = if 0.0 <= f { diff --git a/src/libstd/unstable/intrinsics.rs b/src/libstd/unstable/intrinsics.rs index 349739a5ea63d..190ac9da7fd30 100644 --- a/src/libstd/unstable/intrinsics.rs +++ b/src/libstd/unstable/intrinsics.rs @@ -94,6 +94,7 @@ pub trait TyVisitor { fn visit_u32(&mut self) -> bool; fn visit_u64(&mut self) -> bool; + #[cfg(stage0)] fn visit_float(&mut self) -> bool; fn visit_f32(&mut self) -> bool; fn visit_f64(&mut self) -> bool; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index f2d7ebdd5993f..5056bd5a00d9b 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -765,7 +765,6 @@ impl ToStr for uint_ty { #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum float_ty { - ty_f, ty_f32, ty_f64, } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index f93fc1e81da23..12ad7111f7f40 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -190,7 +190,7 @@ pub fn uint_ty_max(t: uint_ty) -> u64 { } pub fn float_ty_to_str(t: float_ty) -> ~str { - match t { ty_f => ~"f", ty_f32 => ~"f32", ty_f64 => ~"f64" } + match t { ty_f32 => ~"f32", ty_f64 => ~"f64" } } pub fn is_call_expr(e: @Expr) -> bool { diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 24a5f9d5e3c87..bfd1e9cc9943a 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -446,7 +446,6 @@ fn mk_token(cx: @ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr { LIT_FLOAT(fident, fty) => { let s_fty = match fty { - ast::ty_f => ~"ty_f", ast::ty_f32 => ~"ty_f32", ast::ty_f64 => ~"ty_f64" }; diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 640c7c220e5e2..4a384f864b09d 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -530,7 +530,6 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token { None => () } - let mut is_machine_float = false; if rdr.curr == 'f' { bump(rdr); c = rdr.curr; @@ -549,14 +548,10 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token { 32-bit or 64-bit float, it won't be noticed till the back-end. */ } else { - is_float = true; - is_machine_float = true; + fatal_span(rdr, start_bpos, rdr.last_pos, ~"expected `f32` or `f64` suffix"); } } if is_float { - if is_machine_float { - return token::LIT_FLOAT(str_to_ident(num_str), ast::ty_f); - } return token::LIT_FLOAT_UNSUFFIXED(str_to_ident(num_str)); } else { if num_str.len() == 0u { diff --git a/src/test/auxiliary/static_fn_inline_xc_aux.rs b/src/test/auxiliary/static_fn_inline_xc_aux.rs index a17a78bcea773..0cbd4378490d9 100644 --- a/src/test/auxiliary/static_fn_inline_xc_aux.rs +++ b/src/test/auxiliary/static_fn_inline_xc_aux.rs @@ -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; } } } diff --git a/src/test/auxiliary/static_fn_trait_xc_aux.rs b/src/test/auxiliary/static_fn_trait_xc_aux.rs index cc03ac3894304..a0c9edac5e146 100644 --- a/src/test/auxiliary/static_fn_trait_xc_aux.rs +++ b/src/test/auxiliary/static_fn_trait_xc_aux.rs @@ -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; } } } diff --git a/src/test/auxiliary/trait_default_method_xc_aux.rs b/src/test/auxiliary/trait_default_method_xc_aux.rs index 105d7f758f787..123ad24e7a91e 100644 --- a/src/test/auxiliary/trait_default_method_xc_aux.rs +++ b/src/test/auxiliary/trait_default_method_xc_aux.rs @@ -23,7 +23,7 @@ trait B { } impl B for int { } -impl B for bool { } +impl B for bool { } diff --git a/src/test/auxiliary/xc_conditions_4.rs b/src/test/auxiliary/xc_conditions_4.rs index e98e6929970b0..569f22d364417 100644 --- a/src/test/auxiliary/xc_conditions_4.rs +++ b/src/test/auxiliary/xc_conditions_4.rs @@ -16,7 +16,7 @@ pub enum Color { } condition! { - pub oops: (int,float,~str) -> Color; + pub oops: (int,f64,~str) -> Color; } pub trait Thunk { diff --git a/src/test/bench/core-set.rs b/src/test/bench/core-set.rs index a4c07371f6780..138d5795ae188 100644 --- a/src/test/bench/core-set.rs +++ b/src/test/bench/core-set.rs @@ -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, } } diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index fa2b74ef44c63..054b985a55ce2 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -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() { diff --git a/src/test/bench/msgsend-pipes-shared.rs b/src/test/bench/msgsend-pipes-shared.rs index ba7682f5bbd4d..83bb6a37e929c 100644 --- a/src/test/bench/msgsend-pipes-shared.rs +++ b/src/test/bench/msgsend-pipes-shared.rs @@ -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); } diff --git a/src/test/bench/msgsend-pipes.rs b/src/test/bench/msgsend-pipes.rs index 1db73f9a95d12..ad72731875374 100644 --- a/src/test/bench/msgsend-pipes.rs +++ b/src/test/bench/msgsend-pipes.rs @@ -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); } diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index a676e01d9271d..e4d45c6b74a9a 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -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); diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index 1f95e4232ad47..d326fd81518ee 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -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); diff --git a/src/test/bench/noise.rs b/src/test/bench/noise.rs index 1a3a188b86f8d..a424c880c385f 100644 --- a/src/test/bench/noise.rs +++ b/src/test/bench/noise.rs @@ -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: &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, diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 4c246bbe3f706..3b8bd444c170b 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -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 for S2 { } fn main() { - let _ = S::new::(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::(1, 1.0); //~ ERROR this impl has no lifetime parameter - let _: S2 = Trait::new::(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::(1, 1.0); //~ ERROR this trait has no lifetime parameter + let _ = S::new::(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::(1, 1.0); //~ ERROR this impl has no lifetime parameter + let _: S2 = Trait::new::(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::(1, 1.0); //~ ERROR this trait has no lifetime parameter } diff --git a/src/test/compile-fail/block-arg-as-stmt-with-value.rs b/src/test/compile-fail/block-arg-as-stmt-with-value.rs index 294c45093dd6f..71a0b8b7a8e85 100644 --- a/src/test/compile-fail/block-arg-as-stmt-with-value.rs +++ b/src/test/compile-fail/block-arg-as-stmt-with-value.rs @@ -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); } diff --git a/src/test/compile-fail/borrowck-loan-local-as-both-mut-and-imm.rs b/src/test/compile-fail/borrowck-loan-local-as-both-mut-and-imm.rs index db9d8d7ceafba..9d9dd5b1ad8bd 100644 --- a/src/test/compile-fail/borrowck-loan-local-as-both-mut-and-imm.rs +++ b/src/test/compile-fail/borrowck-loan-local-as-both-mut-and-imm.rs @@ -10,7 +10,7 @@ use std::either::{Either, Left, Right}; - fn f(x: &mut Either, y: &Either) -> int { + fn f(x: &mut Either, y: &Either) -> 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 = Left(3); + let mut x: Either = Left(3); println(f(&mut x, &x).to_str()); //~ ERROR cannot borrow } fn h() { - let mut x: Either = Left(3); - let y: &Either = &x; - let z: &mut Either = &mut x; //~ ERROR cannot borrow + let mut x: Either = Left(3); + let y: &Either = &x; + let z: &mut Either = &mut x; //~ ERROR cannot borrow *z = *y; } diff --git a/src/test/compile-fail/float-literal-inference-restrictions.rs b/src/test/compile-fail/float-literal-inference-restrictions.rs index 48dbdd86b11f9..1e58df69f1664 100644 --- a/src/test/compile-fail/float-literal-inference-restrictions.rs +++ b/src/test/compile-fail/float-literal-inference-restrictions.rs @@ -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 } diff --git a/src/test/compile-fail/issue-3973.rs b/src/test/compile-fail/issue-3973.rs index f029921dd1c80..f8f4b0608a57e 100644 --- a/src/test/compile-fail/issue-3973.rs +++ b/src/test/compile-fail/issue-3973.rs @@ -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 } } diff --git a/src/test/compile-fail/issue-6804.rs b/src/test/compile-fail/issue-6804.rs index db72740f483c2..6bc9f7d1b2a6a 100644 --- a/src/test/compile-fail/issue-6804.rs +++ b/src/test/compile-fail/issue-6804.rs @@ -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; diff --git a/src/test/compile-fail/lint-unused-import-tricky-names.rs b/src/test/compile-fail/lint-unused-import-tricky-names.rs index a81a410caceb1..0347c67377944 100644 --- a/src/test/compile-fail/lint-unused-import-tricky-names.rs +++ b/src/test/compile-fail/lint-unused-import-tricky-names.rs @@ -19,7 +19,7 @@ mod issue6633 { pub mod name { pub type a = int; pub mod name { - pub type a = float; + pub type a = f64; } } } diff --git a/src/test/compile-fail/macro-local-data-key-priv.rs b/src/test/compile-fail/macro-local-data-key-priv.rs index a64c5c0958487..463ad958f11b6 100644 --- a/src/test/compile-fail/macro-local-data-key-priv.rs +++ b/src/test/compile-fail/macro-local-data-key-priv.rs @@ -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() { diff --git a/src/test/compile-fail/no-binary-float-literal.rs b/src/test/compile-fail/no-binary-float-literal.rs index 0fa61b1af52ef..2e207f90d36cd 100644 --- a/src/test/compile-fail/no-binary-float-literal.rs +++ b/src/test/compile-fail/no-binary-float-literal.rs @@ -11,7 +11,7 @@ // error-pattern:binary float literal is not supported fn main() { - 0b101010f; + 0b101010f64; 0b101.010; - 0b101p4f; + 0b101p4f64; } diff --git a/src/test/compile-fail/prim-with-args.rs b/src/test/compile-fail/prim-with-args.rs index e60fbf4fc49a8..0587e033a9789 100644 --- a/src/test/compile-fail/prim-with-args.rs +++ b/src/test/compile-fail/prim-with-args.rs @@ -20,7 +20,6 @@ let x: u8; //~ ERROR type parameters are not allowed on this type let x: u16; //~ ERROR type parameters are not allowed on this type let x: u32; //~ ERROR type parameters are not allowed on this type let x: u64; //~ ERROR type parameters are not allowed on this type -let x: float; //~ ERROR type parameters are not allowed on this type let x: char; //~ 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 } diff --git a/src/test/compile-fail/syntax-extension-bytes-unsupported-literal.rs b/src/test/compile-fail/syntax-extension-bytes-unsupported-literal.rs index b7d55385d1c31..2d7ff386b7cc1 100644 --- a/src/test/compile-fail/syntax-extension-bytes-unsupported-literal.rs +++ b/src/test/compile-fail/syntax-extension-bytes-unsupported-literal.rs @@ -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! } diff --git a/src/test/compile-fail/tuple-arity-mismatch.rs b/src/test/compile-fail/tuple-arity-mismatch.rs index 517b3cb59232e..60184464085a5 100644 --- a/src/test/compile-fail/tuple-arity-mismatch.rs +++ b/src/test/compile-fail/tuple-arity-mismatch.rs @@ -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 diff --git a/src/test/debug-info/basic-types.rs b/src/test/debug-info/basic-types.rs index 84d9c2c66cc6e..010d3aada3dcb 100644 --- a/src/test/debug-info/basic-types.rs +++ b/src/test/debug-info/basic-types.rs @@ -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(); diff --git a/src/test/debug-info/borrowed-basic.rs b/src/test/debug-info/borrowed-basic.rs index b02b4be2fd9c0..cdc4ce51b877b 100644 --- a/src/test/debug-info/borrowed-basic.rs +++ b/src/test/debug-info/borrowed-basic.rs @@ -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; diff --git a/src/test/debug-info/borrowed-managed-basic.rs b/src/test/debug-info/borrowed-managed-basic.rs index 35a222ffd0442..917db045edbcc 100644 --- a/src/test/debug-info/borrowed-managed-basic.rs +++ b/src/test/debug-info/borrowed-managed-basic.rs @@ -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; diff --git a/src/test/debug-info/borrowed-unique-basic.rs b/src/test/debug-info/borrowed-unique-basic.rs index ac295783c9f94..48ac507b04d0d 100644 --- a/src/test/debug-info/borrowed-unique-basic.rs +++ b/src/test/debug-info/borrowed-unique-basic.rs @@ -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; diff --git a/src/test/debug-info/by-value-non-immediate-argument.rs b/src/test/debug-info/by-value-non-immediate-argument.rs index 45f8c134f2c2a..6ea0e0b12a3f5 100644 --- a/src/test/debug-info/by-value-non-immediate-argument.rs +++ b/src/test/debug-info/by-value-non-immediate-argument.rs @@ -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(); diff --git a/src/test/debug-info/by-value-self-argument-in-trait-impl.rs b/src/test/debug-info/by-value-self-argument-in-trait-impl.rs index 75e65178546c5..2a5d75be8b3b0 100644 --- a/src/test/debug-info/by-value-self-argument-in-trait-impl.rs +++ b/src/test/debug-info/by-value-self-argument-in-trait-impl.rs @@ -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 } diff --git a/src/test/debug-info/destructured-fn-argument.rs b/src/test/debug-info/destructured-fn-argument.rs index 49bbb7ed2635a..3e139966ff186 100644 --- a/src/test/debug-info/destructured-fn-argument.rs +++ b/src/test/debug-info/destructured-fn-argument.rs @@ -190,7 +190,7 @@ enum Univariant { Unit(i32) } -struct TupleStruct (float, int); +struct TupleStruct (f64, int); fn simple_tuple((a, b): (int, bool)) { diff --git a/src/test/debug-info/destructured-local.rs b/src/test/debug-info/destructured-local.rs index 8115d29857030..d222ad8b914fa 100644 --- a/src/test/debug-info/destructured-local.rs +++ b/src/test/debug-info/destructured-local.rs @@ -134,7 +134,7 @@ enum Univariant { Unit(i32) } -struct TupleStruct (float, int); +struct TupleStruct (f64, int); fn main() { diff --git a/src/test/debug-info/generic-function.rs b/src/test/debug-info/generic-function.rs index 22f565ceee5e3..91bf29f55977a 100644 --- a/src/test/debug-info/generic-function.rs +++ b/src/test/debug-info/generic-function.rs @@ -42,7 +42,7 @@ #[deriving(Clone)] struct Struct { a: int, - b: float + b: f64 } fn dup_tup(t0: &T0, t1: &T1) -> ((T0, T1), (T1, T0)) { diff --git a/src/test/debug-info/generic-static-method-on-struct-and-enum.rs b/src/test/debug-info/generic-static-method-on-struct-and-enum.rs index 8e82f0f27b9f9..bea901a75d040 100644 --- a/src/test/debug-info/generic-static-method-on-struct-and-enum.rs +++ b/src/test/debug-info/generic-static-method-on-struct-and-enum.rs @@ -46,7 +46,7 @@ impl Struct { enum Enum { Variant1 { x: int }, Variant2, - Variant3(float, int, char), + Variant3(f64, int, char), } impl Enum { diff --git a/src/test/debug-info/method-on-tuple-struct.rs b/src/test/debug-info/method-on-tuple-struct.rs index d4354709a86ee..36aded40ca5e0 100644 --- a/src/test/debug-info/method-on-tuple-struct.rs +++ b/src/test/debug-info/method-on-tuple-struct.rs @@ -92,7 +92,7 @@ // check:$21 = -16 // debugger:continue -struct TupleStruct(int, float); +struct TupleStruct(int, f64); impl TupleStruct { diff --git a/src/test/debug-info/static-method-on-struct-and-enum.rs b/src/test/debug-info/static-method-on-struct-and-enum.rs index 0d1ce28094a5a..e4b2e06faf4d1 100644 --- a/src/test/debug-info/static-method-on-struct-and-enum.rs +++ b/src/test/debug-info/static-method-on-struct-and-enum.rs @@ -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 } diff --git a/src/test/debug-info/trait-pointers.rs b/src/test/debug-info/trait-pointers.rs index db02e69cfb875..4bd22c151e4f4 100644 --- a/src/test/debug-info/trait-pointers.rs +++ b/src/test/debug-info/trait-pointers.rs @@ -19,7 +19,7 @@ trait Trait { struct Struct { a: int, - b: float + b: f64 } impl Trait for Struct {} diff --git a/src/test/debug-info/var-captured-in-nested-closure.rs b/src/test/debug-info/var-captured-in-nested-closure.rs index 920052eb80ee7..152ba57ddba16 100644 --- a/src/test/debug-info/var-captured-in-nested-closure.rs +++ b/src/test/debug-info/var-captured-in-nested-closure.rs @@ -50,7 +50,7 @@ struct Struct { a: int, - b: float, + b: f64, c: uint } diff --git a/src/test/debug-info/var-captured-in-sendable-closure.rs b/src/test/debug-info/var-captured-in-sendable-closure.rs index f113c6ea4be77..efc93d135a28c 100644 --- a/src/test/debug-info/var-captured-in-sendable-closure.rs +++ b/src/test/debug-info/var-captured-in-sendable-closure.rs @@ -24,7 +24,7 @@ struct Struct { a: int, - b: float, + b: f64, c: uint } diff --git a/src/test/debug-info/var-captured-in-stack-closure.rs b/src/test/debug-info/var-captured-in-stack-closure.rs index e16539d3396a7..987d19911c497 100644 --- a/src/test/debug-info/var-captured-in-stack-closure.rs +++ b/src/test/debug-info/var-captured-in-stack-closure.rs @@ -30,7 +30,7 @@ struct Struct { a: int, - b: float, + b: f64, c: uint } diff --git a/src/test/run-fail/assert-approx-eq-eps-macro-fail.rs b/src/test/run-fail/assert-approx-eq-eps-macro-fail.rs index c0c20f7af4351..8509bde6d2d07 100644 --- a/src/test/run-fail/assert-approx-eq-eps-macro-fail.rs +++ b/src/test/run-fail/assert-approx-eq-eps-macro-fail.rs @@ -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); } diff --git a/src/test/run-fail/assert-approx-eq-macro-fail.rs b/src/test/run-fail/assert-approx-eq-macro-fail.rs index 43de4f92b63b1..60b6cb216d940 100644 --- a/src/test/run-fail/assert-approx-eq-macro-fail.rs +++ b/src/test/run-fail/assert-approx-eq-macro-fail.rs @@ -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); } diff --git a/src/test/run-pass/assert-approx-eq-macro-success.rs b/src/test/run-pass/assert-approx-eq-macro-success.rs index 5c7c11ef50343..3ea1f896dff31 100644 --- a/src/test/run-pass/assert-approx-eq-macro-success.rs +++ b/src/test/run-pass/assert-approx-eq-macro-success.rs @@ -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); } diff --git a/src/test/run-pass/block-arg-can-be-followed-by-binop.rs b/src/test/run-pass/block-arg-can-be-followed-by-binop.rs index 89e8b0a244a02..e65116f214743 100644 --- a/src/test/run-pass/block-arg-can-be-followed-by-binop.rs +++ b/src/test/run-pass/block-arg-can-be-followed-by-binop.rs @@ -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); } diff --git a/src/test/run-pass/block-arg-can-be-followed-by-block-arg.rs b/src/test/run-pass/block-arg-can-be-followed-by-block-arg.rs index f46f738feac47..ed8641eaf85f9 100644 --- a/src/test/run-pass/block-arg-can-be-followed-by-block-arg.rs +++ b/src/test/run-pass/block-arg-can-be-followed-by-block-arg.rs @@ -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); } diff --git a/src/test/run-pass/block-arg-can-be-followed-by-call.rs b/src/test/run-pass/block-arg-can-be-followed-by-call.rs index d74d90ddacf56..1bb16f6041eec 100644 --- a/src/test/run-pass/block-arg-can-be-followed-by-call.rs +++ b/src/test/run-pass/block-arg-can-be-followed-by-call.rs @@ -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); } diff --git a/src/test/run-pass/block-arg.rs b/src/test/run-pass/block-arg.rs index 18da52ca88f4e..c296a37a17ce0 100644 --- a/src/test/run-pass/block-arg.rs +++ b/src/test/run-pass/block-arg.rs @@ -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); diff --git a/src/test/run-pass/const-binops.rs b/src/test/run-pass/const-binops.rs index b3cb8580f7d64..8ccfd9fa361d0 100644 --- a/src/test/run-pass/const-binops.rs +++ b/src/test/run-pass/const-binops.rs @@ -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; diff --git a/src/test/run-pass/const-contents.rs b/src/test/run-pass/const-contents.rs index 5b31c9a44de51..616826f9f9502 100644 --- a/src/test/run-pass/const-contents.rs +++ b/src/test/run-pass/const-contents.rs @@ -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); diff --git a/src/test/run-pass/const-enum-cast.rs b/src/test/run-pass/const-enum-cast.rs index 616c7567adf47..75e942cb767c8 100644 --- a/src/test/run-pass/const-enum-cast.rs +++ b/src/test/run-pass/const-enum-cast.rs @@ -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); diff --git a/src/test/run-pass/const-rec-and-tup.rs b/src/test/run-pass/const-rec-and-tup.rs index c893a3ea8da35..e6680fe3e8fdb 100644 --- a/src/test/run-pass/const-rec-and-tup.rs +++ b/src/test/run-pass/const-rec-and-tup.rs @@ -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 } diff --git a/src/test/run-pass/deriving-clone-struct.rs b/src/test/run-pass/deriving-clone-struct.rs index 412cc3b3a858c..52858a46ba53d 100644 --- a/src/test/run-pass/deriving-clone-struct.rs +++ b/src/test/run-pass/deriving-clone-struct.rs @@ -22,7 +22,6 @@ struct S { _u32: u32, _u64: u64, - _float: float, _f32: f32, _f64: f64, diff --git a/src/test/run-pass/deriving-via-extension-enum.rs b/src/test/run-pass/deriving-via-extension-enum.rs index 4044c58dc5711..b2974b4be0b39 100644 --- a/src/test/run-pass/deriving-via-extension-enum.rs +++ b/src/test/run-pass/deriving-via-extension-enum.rs @@ -11,7 +11,7 @@ #[deriving(Eq)] enum Foo { Bar(int, int), - Baz(float, float) + Baz(f64, f64) } pub fn main() { diff --git a/src/test/run-pass/deriving-zero.rs b/src/test/run-pass/deriving-zero.rs index 59acc353fed60..2c8271df03bb0 100644 --- a/src/test/run-pass/deriving-zero.rs +++ b/src/test/run-pass/deriving-zero.rs @@ -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, diff --git a/src/test/run-pass/early-vtbl-resolution.rs b/src/test/run-pass/early-vtbl-resolution.rs index 2507c1d6def89..89fee7358a111 100644 --- a/src/test/run-pass/early-vtbl-resolution.rs +++ b/src/test/run-pass/early-vtbl-resolution.rs @@ -19,5 +19,5 @@ fn foo_func>(x: B) -> Option { x.foo() } struct A { a: int } pub fn main() { - let _x: Option = foo_func(0); + let _x: Option = foo_func(0); } diff --git a/src/test/run-pass/enum-disr-val-pretty.rs b/src/test/run-pass/enum-disr-val-pretty.rs index 083e851f9659a..ee2c1ffba11f8 100644 --- a/src/test/run-pass/enum-disr-val-pretty.rs +++ b/src/test/run-pass/enum-disr-val-pretty.rs @@ -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); } diff --git a/src/test/run-pass/enum-variants.rs b/src/test/run-pass/enum-variants.rs index 430823b295073..6d93437971cde 100644 --- a/src/test/run-pass/enum-variants.rs +++ b/src/test/run-pass/enum-variants.rs @@ -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() { diff --git a/src/test/run-pass/explicit-self.rs b/src/test/run-pass/explicit-self.rs index 295f175fca4f7..c090ca3960bf4 100644 --- a/src/test/run-pass/explicit-self.rs +++ b/src/test/run-pass/explicit-self.rs @@ -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) diff --git a/src/test/run-pass/float-literal-inference.rs b/src/test/run-pass/float-literal-inference.rs index d2c872c05345a..b80cdf9fbbd9c 100644 --- a/src/test/run-pass/float-literal-inference.rs +++ b/src/test/run-pass/float-literal-inference.rs @@ -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()); diff --git a/src/test/run-pass/float-nan.rs b/src/test/run-pass/float-nan.rs index b34cc7863b254..9035176a267b1 100644 --- a/src/test/run-pass/float-nan.rs +++ b/src/test/run-pass/float-nan.rs @@ -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()); diff --git a/src/test/run-pass/float-signature.rs b/src/test/run-pass/float-signature.rs index 5193d1e559d29..dae41d34e0526 100644 --- a/src/test/run-pass/float-signature.rs +++ b/src/test/run-pass/float-signature.rs @@ -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); } diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs index 2f5d4380f2e18..39ca7b0b8ad84 100644 --- a/src/test/run-pass/ifmt.rs +++ b/src/test/run-pass/ifmt.rs @@ -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!("\\{"), "{"); diff --git a/src/test/run-pass/issue-3609.rs b/src/test/run-pass/issue-3609.rs index c0bd5aa2a6883..fdd26478a99dc 100644 --- a/src/test/run-pass/issue-3609.rs +++ b/src/test/run-pass/issue-3609.rs @@ -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 diff --git a/src/test/run-pass/issue-3743.rs b/src/test/run-pass/issue-3743.rs index be136160df43a..13455bd4ca83e 100644 --- a/src/test/run-pass/issue-3743.rs +++ b/src/test/run-pass/issue-3743.rs @@ -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> Mul 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 for float { +// Implementation of 'f64 as right-hand-side of Vec2::Mul' +impl RhsOfVec2Mul 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 } diff --git a/src/test/run-pass/issue-3753.rs b/src/test/run-pass/issue-3753.rs index 0a35120cd1e57..49759f3b85b98 100644 --- a/src/test/run-pass/issue-3753.rs +++ b/src/test/run-pass/issue-3753.rs @@ -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)); } diff --git a/src/test/run-pass/issue-4107.rs b/src/test/run-pass/issue-4107.rs index f922857fb3f3f..2ed662e9f2d60 100644 --- a/src/test/run-pass/issue-4107.rs +++ b/src/test/run-pass/issue-4107.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let _id: &Mat2 = &Matrix::identity(); + let _id: &Mat2 = &Matrix::identity(); } pub trait Index { } diff --git a/src/test/run-pass/issue-5754.rs b/src/test/run-pass/issue-5754.rs index c440fe525eef9..b2eeedfbdc922 100644 --- a/src/test/run-pass/issue-5754.rs +++ b/src/test/run-pass/issue-5754.rs @@ -9,8 +9,8 @@ // except according to those terms. struct TwoDoubles { - r: float, - i: float + r: f64, + i: f64 } extern "C" { diff --git a/src/test/run-pass/issue-7222.rs b/src/test/run-pass/issue-7222.rs index 98c0064d0ec1f..5db170fd52100 100644 --- a/src/test/run-pass/issue-7222.rs +++ b/src/test/run-pass/issue-7222.rs @@ -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 => (), diff --git a/src/test/run-pass/macro-local-data-key.rs b/src/test/run-pass/macro-local-data-key.rs index 23f418cfc691e..e03256bfe499d 100644 --- a/src/test/run-pass/macro-local-data-key.rs +++ b/src/test/run-pass/macro-local-data-key.rs @@ -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() { diff --git a/src/test/run-pass/mid-path-type-params.rs b/src/test/run-pass/mid-path-type-params.rs index 09435962ef748..bc4f4273dfbf8 100644 --- a/src/test/run-pass/mid-path-type-params.rs +++ b/src/test/run-pass/mid-path-type-params.rs @@ -27,7 +27,7 @@ impl Trait for S2 { } pub fn main() { - let _ = S::::new::(1, 1.0); - let _: S2 = Trait::::new::(1, 1.0); + let _ = S::::new::(1, 1.0); + let _: S2 = Trait::::new::(1, 1.0); } diff --git a/src/test/run-pass/numeric-method-autoexport.rs b/src/test/run-pass/numeric-method-autoexport.rs index 569ccf5335ea0..f2df3fc66ea8c 100644 --- a/src/test/run-pass/numeric-method-autoexport.rs +++ b/src/test/run-pass/numeric-method-autoexport.rs @@ -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); } diff --git a/src/test/run-pass/pure-fmt.rs b/src/test/run-pass/pure-fmt.rs index f5dc7c1c1d307..d7cf9f2cd2f78 100644 --- a/src/test/run-pass/pure-fmt.rs +++ b/src/test/run-pass/pure-fmt.rs @@ -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 { diff --git a/src/test/run-pass/reflect-visit-data.rs b/src/test/run-pass/reflect-visit-data.rs index be276478522ba..85cc8b224f689 100644 --- a/src/test/run-pass/reflect-visit-data.rs +++ b/src/test/run-pass/reflect-visit-data.rs @@ -152,13 +152,6 @@ impl TyVisitor for ptr_visit_adaptor { true } - fn visit_float(&mut self) -> bool { - self.align_to::(); - if ! self.inner.visit_float() { return false; } - self.bump_past::(); - true - } - fn visit_f32(&mut self) -> bool { self.align_to::(); 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 } diff --git a/src/test/run-pass/reflect-visit-type.rs b/src/test/run-pass/reflect-visit-type.rs index 7b14b36df7d45..0afc5dd1b17ea 100644 --- a/src/test/run-pass/reflect-visit-type.rs +++ b/src/test/run-pass/reflect-visit-type.rs @@ -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 } diff --git a/src/test/run-pass/sendfn-generic-fn.rs b/src/test/run-pass/sendfn-generic-fn.rs index b7d6a0f391562..7cc83e2ff546e 100644 --- a/src/test/run-pass/sendfn-generic-fn.rs +++ b/src/test/run-pass/sendfn-generic-fn.rs @@ -24,15 +24,15 @@ fn make_generic_record(a: A, b: B) -> Pair { return Pair {a: a, b: b}; } -fn test05_start(f: &~fn(v: float, v: ~str) -> Pair) { - let p = (*f)(22.22f, ~"Hi"); +fn test05_start(f: &~fn(v: f64, v: ~str) -> Pair) { + 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(f: extern fn(&~fn(A,B)->Pair)) { } fn test05() { - spawn::(test05_start); + spawn::(test05_start); } diff --git a/src/test/run-pass/static-fn-inline-xc.rs b/src/test/run-pass/static-fn-inline-xc.rs index 000f43684d435..e3441661d5b19 100644 --- a/src/test/run-pass/static-fn-inline-xc.rs +++ b/src/test/run-pass/static-fn-inline-xc.rs @@ -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); } diff --git a/src/test/run-pass/static-fn-trait-xc.rs b/src/test/run-pass/static-fn-trait-xc.rs index 55db2018aaed0..41665871451f0 100644 --- a/src/test/run-pass/static-fn-trait-xc.rs +++ b/src/test/run-pass/static-fn-trait-xc.rs @@ -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); } diff --git a/src/test/run-pass/static-methods-in-traits2.rs b/src/test/run-pass/static-methods-in-traits2.rs index 20e6efa11f090..a73978ce73c63 100644 --- a/src/test/run-pass/static-methods-in-traits2.rs +++ b/src/test/run-pass/static-methods-in-traits2.rs @@ -2,18 +2,18 @@ pub trait Number: NumConv { fn from(n: T) -> Self; } -impl Number for float { - fn from(n: T) -> float { n.to_float() } +impl Number for f64 { + fn from(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); } diff --git a/src/test/run-pass/struct-like-variant-construct.rs b/src/test/run-pass/struct-like-variant-construct.rs index 4e16b5cb4cc11..42f119cbe396f 100644 --- a/src/test/run-pass/struct-like-variant-construct.rs +++ b/src/test/run-pass/struct-like-variant-construct.rs @@ -14,8 +14,8 @@ enum Foo { b: int }, Baz { - c: float, - d: float + c: f64, + d: f64 } } diff --git a/src/test/run-pass/struct-like-variant-match.rs b/src/test/run-pass/struct-like-variant-match.rs index ef558de433fe8..b0f2f65b3f41b 100644 --- a/src/test/run-pass/struct-like-variant-match.rs +++ b/src/test/run-pass/struct-like-variant-match.rs @@ -14,8 +14,8 @@ enum Foo { y: int }, Baz { - x: float, - y: float + x: f64, + y: f64 } } diff --git a/src/test/run-pass/struct-return.rs b/src/test/run-pass/struct-return.rs index 1cdc8d3826cc8..7b5988b9b3dd8 100644 --- a/src/test/run-pass/struct-return.rs +++ b/src/test/run-pass/struct-return.rs @@ -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); diff --git a/src/test/run-pass/supported-cast.rs b/src/test/run-pass/supported-cast.rs index cfa721a4ed311..090e932d8dc8b 100644 --- a/src/test/run-pass/supported-cast.rs +++ b/src/test/run-pass/supported-cast.rs @@ -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); diff --git a/src/test/run-pass/tag-variant-disr-val.rs b/src/test/run-pass/tag-variant-disr-val.rs index a6252bf5f38d9..8eed2653a901a 100644 --- a/src/test/run-pass/tag-variant-disr-val.rs +++ b/src/test/run-pass/tag-variant-disr-val.rs @@ -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); } diff --git a/src/test/run-pass/trait-default-method-bound-subst4.rs b/src/test/run-pass/trait-default-method-bound-subst4.rs index 4804dc273479b..fdc42e58f8cac 100644 --- a/src/test/run-pass/trait-default-method-bound-subst4.rs +++ b/src/test/run-pass/trait-default-method-bound-subst4.rs @@ -20,6 +20,6 @@ fn f>(i: V, j: uint) -> uint { } pub fn main () { - assert_eq!(f::(0, 2u), 2u); + assert_eq!(f::(0, 2u), 2u); assert_eq!(f::(0, 2u), 2u); } diff --git a/src/test/run-pass/trait-default-method-xc.rs b/src/test/run-pass/trait-default-method-xc.rs index baf4cf45b3ce8..1013a1273071b 100644 --- a/src/test/run-pass/trait-default-method-xc.rs +++ b/src/test/run-pass/trait-default-method-xc.rs @@ -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::::staticthing::(&0i, 3.14, 1), (3.14, 1)); + assert_eq!(B::::staticthing::(&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)); diff --git a/src/test/run-pass/trait-inheritance-num2.rs b/src/test/run-pass/trait-inheritance-num2.rs index babe1a18fa123..994941b4b2266 100644 --- a/src/test/run-pass/trait-inheritance-num2.rs +++ b/src/test/run-pass/trait-inheritance-num2.rs @@ -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 {} impl FloatExt for f32 {} impl FloatExt for f64 {} -impl FloatExt for float {} fn test_float_ext(n: T) { println!("{}", n < n) } diff --git a/src/test/run-pass/trait-inheritance-self-in-supertype.rs b/src/test/run-pass/trait-inheritance-self-in-supertype.rs index 474e0cfe1db29..fac29e68525cf 100644 --- a/src/test/run-pass/trait-inheritance-self-in-supertype.rs +++ b/src/test/run-pass/trait-inheritance-self-in-supertype.rs @@ -2,7 +2,7 @@ use std::num; -pub static FUZZY_EPSILON: float = 0.1; +pub static FUZZY_EPSILON: f64 = 0.1; pub trait FuzzyEq { fn fuzzy_eq(&self, other: &Self) -> bool; diff --git a/src/test/run-pass/typeck-macro-interaction-issue-8852.rs b/src/test/run-pass/typeck-macro-interaction-issue-8852.rs index 8de2c1e0814b7..66a1ebe26cd54 100644 --- a/src/test/run-pass/typeck-macro-interaction-issue-8852.rs +++ b/src/test/run-pass/typeck-macro-interaction-issue-8852.rs @@ -1,6 +1,6 @@ enum T { A(int), - B(float) + B(f64) } macro_rules! test( diff --git a/src/test/run-pass/xcrate-address-insignificant.rs b/src/test/run-pass/xcrate-address-insignificant.rs index 1bf3763834a55..33f958f20bcb7 100644 --- a/src/test/run-pass/xcrate-address-insignificant.rs +++ b/src/test/run-pass/xcrate-address-insignificant.rs @@ -14,5 +14,5 @@ extern mod foo(name = "xcrate_address_insignificant"); fn main() { - assert_eq!(foo::foo::(), foo::bar()); + assert_eq!(foo::foo::(), foo::bar()); }