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

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

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

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

Closes #6592

The mailing list thread, for reference:

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

View file

@ -363,19 +363,17 @@ A _floating-point literal_ has one of two forms:
second decimal literal. second decimal literal.
* A single _decimal literal_ followed by an _exponent_. * A single _decimal literal_ followed by an _exponent_.
By default, a floating-point literal is of type `float`. A By default, a floating-point literal has a generic type, but will fall back to
floating-point literal may be followed (immediately, without any `f64`. A floating-point literal may be followed (immediately, without any
spaces) by a _floating-point suffix_, which changes the type of the spaces) by a _floating-point suffix_, which changes the type of the literal.
literal. There are three floating-point suffixes: `f` (for the base There are two floating-point suffixes: `f32`, and `f64` (the 32-bit and 64-bit
`float` type), `f32`, and `f64` (the 32-bit and 64-bit floating point floating point types).
types).
Examples of floating-point literals of various forms: Examples of floating-point literals of various forms:
~~~~ ~~~~
123.0; // type float 123.0; // type f64
0.1; // type float 0.1; // type f64
3f; // type float
0.1f32; // type f32 0.1f32; // type f32
12E+99_f64; // type f64 12E+99_f64; // type f64
~~~~ ~~~~
@ -1179,8 +1177,8 @@ a = Cat;
Enumeration constructors can have either named or unnamed fields: Enumeration constructors can have either named or unnamed fields:
~~~~ ~~~~
enum Animal { enum Animal {
Dog (~str, float), Dog (~str, f64),
Cat { name: ~str, weight: float } Cat { name: ~str, weight: f64 }
} }
let mut a: Animal = Dog(~"Cocoa", 37.2); let mut a: Animal = Dog(~"Cocoa", 37.2);
@ -1344,17 +1342,17 @@ For example:
trait Num { trait Num {
fn from_int(n: int) -> Self; fn from_int(n: int) -> Self;
} }
impl Num for float { impl Num for f64 {
fn from_int(n: int) -> float { n as float } 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 Traits may inherit from other traits. For example, in
~~~~ ~~~~
trait Shape { fn area() -> float; } trait Shape { fn area() -> f64; }
trait Circle : Shape { fn radius() -> float; } trait Circle : Shape { fn radius() -> f64; }
~~~~ ~~~~
the syntax `Circle : Shape` means that types that implement `Circle` must also have an implementation for `Shape`. 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`: Referring to the previous example of `trait Circle : Shape`:
~~~ ~~~
# trait Shape { fn area(&self) -> float; } # trait Shape { fn area(&self) -> f64; }
# trait Circle : Shape { fn radius(&self) -> float; } # trait Circle : Shape { fn radius(&self) -> f64; }
fn radius_times_area<T: Circle>(c: T) -> float { fn radius_times_area<T: Circle>(c: T) -> f64 {
// `c` is both a Circle and a Shape // `c` is both a Circle and a Shape
c.radius() * c.area() c.radius() * c.area()
} }
@ -1378,10 +1376,10 @@ fn radius_times_area<T: Circle>(c: T) -> float {
Likewise, supertrait methods may also be called on trait objects. Likewise, supertrait methods may also be called on trait objects.
~~~ {.xfail-test} ~~~ {.xfail-test}
# trait Shape { fn area(&self) -> float; } # trait Shape { fn area(&self) -> f64; }
# trait Circle : Shape { fn radius(&self) -> float; } # trait Circle : Shape { fn radius(&self) -> f64; }
# impl Shape for int { fn area(&self) -> float { 0.0 } } # impl Shape for int { fn area(&self) -> f64 { 0.0 } }
# impl Circle for int { fn radius(&self) -> float { 0.0 } } # impl Circle for int { fn radius(&self) -> f64 { 0.0 } }
# let mycircle = 0; # let mycircle = 0;
let mycircle: Circle = @mycircle as @Circle; 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`. Implementations are defined with the keyword `impl`.
~~~~ ~~~~
# struct Point {x: float, y: float}; # struct Point {x: f64, y: f64};
# type Surface = int; # 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; } # trait Shape { fn draw(&self, Surface); fn bounding_box(&self) -> BoundingBox; }
# fn do_draw_circle(s: Surface, c: Circle) { } # fn do_draw_circle(s: Surface, c: Circle) { }
struct Circle { struct Circle {
radius: float, radius: f64,
center: Point, center: Point,
} }
@ -1970,7 +1968,7 @@ values.
~~~~~~~~ {.tuple} ~~~~~~~~ {.tuple}
(0,); (0,);
(0f, 4.5f); (0.0, 4.5);
("a", 4u, true); ("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: The following are examples of structure expressions:
~~~~ ~~~~
# struct Point { x: float, y: float } # struct Point { x: f64, y: f64 }
# struct TuplePoint(float, float); # struct TuplePoint(f64, f64);
# mod game { pub struct User<'self> { name: &'self str, age: uint, score: uint } } # mod game { pub struct User<'self> { name: &'self str, age: uint, score: uint } }
# struct Cookie; fn some_fn<T>(t: T) {} # struct Cookie; fn some_fn<T>(t: T) {}
Point {x: 10f, y: 20f}; Point {x: 10.0, y: 20.0};
TuplePoint(10f, 20f); TuplePoint(10.0, 20.0);
let u = game::User {name: "Joe", age: 35, score: 100_000}; let u = game::User {name: "Joe", age: 35, score: 100_000};
some_fn::<Cookie>(Cookie); some_fn::<Cookie>(Cookie);
~~~~ ~~~~
@ -2248,12 +2246,12 @@ Any other cast is unsupported and will fail to compile.
An example of an `as` expression: An example of an `as` expression:
~~~~ ~~~~
# fn sum(v: &[float]) -> float { 0.0 } # fn sum(v: &[f64]) -> f64 { 0.0 }
# fn len(v: &[float]) -> int { 0 } # fn len(v: &[f64]) -> int { 0 }
fn avg(v: &[float]) -> float { fn avg(v: &[f64]) -> f64 {
let sum: float = sum(v); let sum: f64 = sum(v);
let sz: float = len(v) as float; let sz: f64 = len(v) as f64;
return sum / sz; 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.
#### 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 ### Textual types
The types `char` and `str` hold textual data. The types `char` and `str` hold textual data.

View file

@ -32,7 +32,7 @@ where you would like to use data for a short time.
As an example, consider a simple struct type `Point`: 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 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: 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 on_the_stack : Point = Point {x: 3.0, y: 4.0};
let managed_box : @Point = @Point {x: 5.0, y: 1.0}; let managed_box : @Point = @Point {x: 5.0, y: 1.0};
let owned_box : ~Point = ~Point {x: 7.0, y: 9.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: this:
~~~ ~~~
# struct Point {x: float, y: float} # struct Point {x: f64, y: f64}
# fn sqrt(f: float) -> float { 0f } # fn sqrt(f: f64) -> f64 { 0.0 }
fn compute_distance(p1: &Point, p2: &Point) -> float { fn compute_distance(p1: &Point, p2: &Point) -> f64 {
let x_d = p1.x - p2.x; let x_d = p1.x - p2.x;
let y_d = p1.y - p2.y; let y_d = p1.y - p2.y;
sqrt(x_d * x_d + y_d * y_d) 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: 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 on_the_stack : Point = Point{x: 3.0, y: 4.0};
# let managed_box : @Point = @Point{x: 5.0, y: 1.0}; # let managed_box : @Point = @Point{x: 5.0, y: 1.0};
# let owned_box : ~Point = ~Point{x: 7.0, y: 9.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(&on_the_stack, managed_box);
compute_distance(managed_box, owned_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: 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}; 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`: 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}; 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: 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 tmp = Point {x: 3.0, y: 4.0};
let on_the_stack2 : &Point = &tmp; let on_the_stack2 : &Point = &tmp;
~~~ ~~~
@ -140,36 +140,36 @@ individual array elements. For example, consider this type definition
for `rectangle`: for `rectangle`:
~~~ ~~~
struct Point {x: float, y: float} // as before struct Point {x: f64, y: f64} // as before
struct Size {w: float, h: float} // as before struct Size {w: f64, h: f64} // as before
struct Rectangle {origin: Point, size: Size} struct Rectangle {origin: Point, size: Size}
~~~ ~~~
Now, as before, we can define rectangles in a few different ways: Now, as before, we can define rectangles in a few different ways:
~~~ ~~~
# struct Point {x: float, y: float} # struct Point {x: f64, y: f64}
# struct Size {w: float, h: float} // as before # struct Size {w: f64, h: f64} // as before
# struct Rectangle {origin: Point, size: Size} # struct Rectangle {origin: Point, size: Size}
let rect_stack = &Rectangle {origin: Point {x: 1f, y: 2f}, let rect_stack = &Rectangle {origin: Point {x: 1.0, y: 2.0},
size: Size {w: 3f, h: 4f}}; size: Size {w: 3.0, h: 4.0}};
let rect_managed = @Rectangle {origin: Point {x: 3f, y: 4f}, let rect_managed = @Rectangle {origin: Point {x: 3.0, y: 4.0},
size: Size {w: 3f, h: 4f}}; size: Size {w: 3.0, h: 4.0}};
let rect_owned = ~Rectangle {origin: Point {x: 5f, y: 6f}, let rect_owned = ~Rectangle {origin: Point {x: 5.0, y: 6.0},
size: Size {w: 3f, h: 4f}}; size: Size {w: 3.0, h: 4.0}};
~~~ ~~~
In each case, we can extract out individual subcomponents with the `&` In each case, we can extract out individual subcomponents with the `&`
operator. For example, I could write: operator. For example, I could write:
~~~ ~~~
# struct Point {x: float, y: float} // as before # struct Point {x: f64, y: f64} // as before
# struct Size {w: float, h: float} // as before # struct Size {w: f64, h: f64} // as before
# struct Rectangle {origin: Point, size: Size} # struct Rectangle {origin: Point, size: Size}
# let rect_stack = &Rectangle {origin: Point {x: 1f, y: 2f}, 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: 3f, y: 4f}, size: Size {w: 3f, h: 4f}}; # 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: 5f, y: 6f}, size: Size {w: 3f, h: 4f}}; # 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) -> float { 0f } # fn compute_distance(p1: &Point, p2: &Point) -> f64 { 0.0 }
compute_distance(&rect_stack.origin, &rect_managed.origin); compute_distance(&rect_stack.origin, &rect_managed.origin);
~~~ ~~~
@ -375,10 +375,10 @@ As an example, lets look at the following `shape` type that can
represent both rectangles and circles: represent both rectangles and circles:
~~~ ~~~
struct Point {x: float, y: float}; // as before struct Point {x: f64, y: f64}; // as before
struct Size {w: float, h: float}; // as before struct Size {w: f64, h: f64}; // as before
enum Shape { enum Shape {
Circle(Point, float), // origin, radius Circle(Point, f64), // origin, radius
Rectangle(Point, Size) // upper-left, dimensions Rectangle(Point, Size) // upper-left, dimensions
} }
~~~ ~~~
@ -388,14 +388,14 @@ function takes a borrowed pointer to a shape, to avoid the need for
copying. copying.
~~~ ~~~
# struct Point {x: float, y: float}; // as before # struct Point {x: f64, y: f64}; // as before
# struct Size {w: float, h: float}; // as before # struct Size {w: f64, h: f64}; // as before
# enum Shape { # enum Shape {
# Circle(Point, float), // origin, radius # Circle(Point, f64), // origin, radius
# Rectangle(Point, Size) // upper-left, dimensions # Rectangle(Point, Size) // upper-left, dimensions
# } # }
# static tau: float = 6.28f; # static tau: f64 = 6.28;
fn compute_area(shape: &Shape) -> float { fn compute_area(shape: &Shape) -> f64 {
match *shape { match *shape {
Circle(_, radius) => 0.5 * tau * radius * radius, Circle(_, radius) => 0.5 * tau * radius * radius,
Rectangle(_, ref size) => size.w * size.h Rectangle(_, ref size) => size.w * size.h
@ -424,10 +424,10 @@ Stack Memory
+-------+ +---------------+ +-------+ +---------------+
| shape | ------> | rectangle( | | shape | ------> | rectangle( |
+-------+ | {x: float, | +-------+ | {x: f64, |
| size | -+ | y: float}, | | size | -+ | y: f64}, |
+-------+ +----> | {w: float, | +-------+ +----> | {w: f64, |
| h: float}) | | h: f64}) |
+---------------+ +---------------+
~~~ ~~~
@ -449,16 +449,16 @@ Stack Memory
+-------+ +---------------+ +-------+ +---------------+
| shape | ------> | circle( | | shape | ------> | circle( |
+-------+ | {x: float, | +-------+ | {x: f64, |
| size | -+ | y: float}, | | size | -+ | y: f64}, |
+-------+ +----> | float) | +-------+ +----> | 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 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. safety violation.
So, in fact, for every `ref` binding, the compiler will impose the 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: For example, we could write a subroutine like this:
~~~ ~~~
struct Point {x: float, y: float} struct Point {x: f64, y: f64}
fn get_x<'r>(p: &'r Point) -> &'r float { &p.x } fn get_x<'r>(p: &'r Point) -> &'r f64 { &p.x }
~~~ ~~~
Here, the function `get_x()` returns a pointer into the structure it Here, the function `get_x()` returns a pointer into the structure it
was given. The type of the parameter (`&'r Point`) and return type 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 far. Here the identifier `r` names the lifetime of the pointer
explicitly. So in effect, this function declares that it takes a explicitly. So in effect, this function declares that it takes a
pointer with lifetime `r` and returns a pointer with that same pointer with lifetime `r` and returns a pointer with that same
@ -525,8 +525,8 @@ To emphasize this point, lets look at a variation on the example, this
time one that does not compile: time one that does not compile:
~~~ {.xfail-test} ~~~ {.xfail-test}
struct Point {x: float, y: float} struct Point {x: f64, y: f64}
fn get_x_sh(p: @Point) -> &float { fn get_x_sh(p: @Point) -> &f64 {
&p.x // Error reported here &p.x // Error reported here
} }
~~~ ~~~
@ -564,14 +564,14 @@ for grouping of parameters by lifetime. For example, consider this
function: function:
~~~ ~~~
# struct Point {x: float, y: float}; // as before # struct Point {x: f64, y: f64}; // as before
# struct Size {w: float, h: float}; // as before # struct Size {w: f64, h: f64}; // as before
# enum Shape { # enum Shape {
# Circle(Point, float), // origin, radius # Circle(Point, f64), // origin, radius
# Rectangle(Point, Size) // upper-left, dimensions # Rectangle(Point, Size) // upper-left, dimensions
# } # }
# fn compute_area(shape: &Shape) -> float { 0f } # fn compute_area(shape: &Shape) -> f64 { 0.0 }
fn select<'r, T>(shape: &'r Shape, threshold: float, fn select<'r, T>(shape: &'r Shape, threshold: f64,
a: &'r T, b: &'r T) -> &'r T { a: &'r T, b: &'r T) -> &'r T {
if compute_area(shape) > threshold {a} else {b} if compute_area(shape) > threshold {a} else {b}
} }
@ -584,20 +584,20 @@ region parameters*. This may be overly conservative, as in this
example: example:
~~~ ~~~
# struct Point {x: float, y: float}; // as before # struct Point {x: f64, y: f64}; // as before
# struct Size {w: float, h: float}; // as before # struct Size {w: f64, h: f64}; // as before
# enum Shape { # enum Shape {
# Circle(Point, float), // origin, radius # Circle(Point, f64), // origin, radius
# Rectangle(Point, Size) // upper-left, dimensions # Rectangle(Point, Size) // upper-left, dimensions
# } # }
# fn compute_area(shape: &Shape) -> float { 0f } # fn compute_area(shape: &Shape) -> f64 { 0.0 }
# fn select<'r, T>(shape: &Shape, threshold: float, # fn select<'r, T>(shape: &Shape, threshold: f64,
# a: &'r T, b: &'r T) -> &'r T { # a: &'r T, b: &'r T) -> &'r T {
# if compute_area(shape) > threshold {a} else {b} # if compute_area(shape) > threshold {a} else {b}
# } # }
// -+ r // -+ r
fn select_based_on_unit_circle<'r, T>( // |-+ B 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.); // | | let shape = Circle(Point {x: 0., y: 0.}, 1.); // | |
select(&shape, threshold, a, b) // | | 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: returned. Here is how the new `select()` might look:
~~~ ~~~
# struct Point {x: float, y: float}; // as before # struct Point {x: f64, y: f64}; // as before
# struct Size {w: float, h: float}; // as before # struct Size {w: f64, h: f64}; // as before
# enum Shape { # enum Shape {
# Circle(Point, float), // origin, radius # Circle(Point, f64), // origin, radius
# Rectangle(Point, Size) // upper-left, dimensions # Rectangle(Point, Size) // upper-left, dimensions
# } # }
# fn compute_area(shape: &Shape) -> float { 0f } # fn compute_area(shape: &Shape) -> f64 { 0.0 }
fn select<'r, 'tmp, T>(shape: &'tmp Shape, threshold: float, fn select<'r, 'tmp, T>(shape: &'tmp Shape, threshold: f64,
a: &'r T, b: &'r T) -> &'r T { a: &'r T, b: &'r T) -> &'r T {
if compute_area(shape) > threshold {a} else {b} 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: concise to just omit the named lifetime for `shape` altogether:
~~~ ~~~
# struct Point {x: float, y: float}; // as before # struct Point {x: f64, y: f64}; // as before
# struct Size {w: float, h: float}; // as before # struct Size {w: f64, h: f64}; // as before
# enum Shape { # enum Shape {
# Circle(Point, float), // origin, radius # Circle(Point, f64), // origin, radius
# Rectangle(Point, Size) // upper-left, dimensions # Rectangle(Point, Size) // upper-left, dimensions
# } # }
# fn compute_area(shape: &Shape) -> float { 0f } # fn compute_area(shape: &Shape) -> f64 { 0.0 }
fn select<'r, T>(shape: &Shape, threshold: float, fn select<'r, T>(shape: &Shape, threshold: f64,
a: &'r T, b: &'r T) -> &'r T { a: &'r T, b: &'r T) -> &'r T {
if compute_area(shape) > threshold {a} else {b} if compute_area(shape) > threshold {a} else {b}
} }

View file

@ -331,12 +331,12 @@ a single large vector of floats. Each task needs the full vector to perform its
# use std::rand; # use std::rand;
use extra::arc::Arc; use extra::arc::Arc;
fn pnorm(nums: &~[float], p: uint) -> float { fn pnorm(nums: &~[f64], p: uint) -> f64 {
nums.iter().fold(0.0, |a,b| a+(*b).pow(&(p as float)) ).pow(&(1f / (p as float))) nums.iter().fold(0.0, |a,b| a+(*b).pow(&(p as f64)) ).pow(&(1.0 / (p as f64)))
} }
fn main() { fn main() {
let numbers = vec::from_fn(1000000, |_| rand::random::<float>()); let numbers = vec::from_fn(1000000, |_| rand::random::<f64>());
println!("Inf-norm = {}", *numbers.iter().max().unwrap()); println!("Inf-norm = {}", *numbers.iter().max().unwrap());
let numbers_arc = Arc::new(numbers); let numbers_arc = Arc::new(numbers);
@ -346,7 +346,7 @@ fn main() {
chan.send(numbers_arc.clone()); chan.send(numbers_arc.clone());
do spawn { do spawn {
let local_arc : Arc<~[float]> = port.recv(); let local_arc : Arc<~[f64]> = port.recv();
let task_numbers = local_arc.get(); let task_numbers = local_arc.get();
println!("{}-norm = {}", num, pnorm(task_numbers, num)); println!("{}-norm = {}", num, pnorm(task_numbers, num));
} }
@ -361,7 +361,7 @@ created by the line
# use extra::arc::Arc; # use extra::arc::Arc;
# use std::vec; # use std::vec;
# use std::rand; # use std::rand;
# let numbers = vec::from_fn(1000000, |_| rand::random::<float>()); # let numbers = vec::from_fn(1000000, |_| rand::random::<f64>());
let numbers_arc=Arc::new(numbers); let numbers_arc=Arc::new(numbers);
~~~ ~~~
and a clone of it is sent to each task 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 extra::arc::Arc;
# use std::vec; # use std::vec;
# use std::rand; # use std::rand;
# let numbers=vec::from_fn(1000000, |_| rand::random::<float>()); # let numbers=vec::from_fn(1000000, |_| rand::random::<f64>());
# let numbers_arc = Arc::new(numbers); # let numbers_arc = Arc::new(numbers);
# let (port, chan) = stream(); # let (port, chan) = stream();
chan.send(numbers_arc.clone()); chan.send(numbers_arc.clone());
@ -381,11 +381,11 @@ Each task recovers the underlying data by
# use extra::arc::Arc; # use extra::arc::Arc;
# use std::vec; # use std::vec;
# use std::rand; # use std::rand;
# let numbers=vec::from_fn(1000000, |_| rand::random::<float>()); # let numbers=vec::from_fn(1000000, |_| rand::random::<f64>());
# let numbers_arc=Arc::new(numbers); # let numbers_arc=Arc::new(numbers);
# let (port, chan) = stream(); # let (port, chan) = stream();
# chan.send(numbers_arc.clone()); # 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(); let task_numbers = local_arc.get();
~~~ ~~~
and can use it as if it were local. and can use it as if it were local.

View file

@ -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. 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 = MONSTER_FACTOR * 10.0;
let monster_size: int = 50; let monster_size: int = 50;
~~~~ ~~~~
Local variables may shadow earlier declarations, as in the previous example: 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 `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 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 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 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`. Floating-point numbers are written `0.0`, `1e6`, or `2.1e-4`.
Like integers, floating-point literals are inferred to the correct type. 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`. 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. expression to the given type.
~~~~ ~~~~
let x: float = 4.0; let x: f64 = 4.0;
let y: uint = x as uint; let y: uint = x as uint;
assert!(y == 4u); 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 matching in order to bind names to the contents of data
types. 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 > are explained in section 5.3. For now you can think of tuples as a list of
> items. > items.
~~~~ ~~~~
use std::float; use std::f64;
use std::num::atan; use std::num::atan;
fn angle(vector: (float, float)) -> float { fn angle(vector: (f64, f64)) -> f64 {
let pi = float::consts::pi; let pi = f64::consts::pi;
match vector { match vector {
(0f, y) if y < 0f => 1.5 * pi, (0.0, y) if y < 0.0 => 1.5 * pi,
(0f, y) => 0.5 * pi, (0.0, y) => 0.5 * pi,
(x, y) => atan(y / x) (x, y) => atan(y / x)
} }
} }
~~~~ ~~~~
A variable name in a pattern matches any value, *and* binds that name 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 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 the second element. `(x, y)` matches any two-element tuple, and binds both
elements to variables. elements to variables.
@ -583,8 +583,8 @@ operator to access struct fields, as in `mypoint.x`.
~~~~ ~~~~
struct Point { struct Point {
x: float, x: f64,
y: float 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. struct without inherited mutability would result in a type error.
~~~~ {.xfail-test} ~~~~ {.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 mut mypoint = Point { x: 1.0, y: 1.0 };
let origin = Point { x: 0.0, y: 0.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, ... }`: `Name { fieldname: pattern, ... }`:
~~~~ ~~~~
# struct Point { x: float, y: float } # struct Point { x: f64, y: f64 }
# let mypoint = Point { x: 0.0, y: 0.0 }; # let mypoint = Point { x: 0.0, y: 0.0 };
match mypoint { match mypoint {
Point { x: 0.0, y: yy } => { println(yy.to_str()); } 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. 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 }; # let mypoint = Point { x: 0.0, y: 0.0 };
match mypoint { match mypoint {
Point { x, _ } => { println(x.to_str()) } 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: example, consider the type shown earlier:
~~~~ ~~~~
# struct Point { x: float, y: float } # struct Point { x: f64, y: f64 }
enum Shape { enum Shape {
Circle(Point, float), Circle(Point, f64),
Rectangle(Point, Point) Rectangle(Point, Point)
} }
~~~~ ~~~~
A value of this type is either a `Circle`, in which case it contains a 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 two `Point` structs. The run-time representation of such a value
includes an identifier of the actual form that it holds, much like the includes an identifier of the actual form that it holds, much like the
"tagged union" pattern in C, but with better static guarantees. "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 The above declaration will define a type `Shape` that can refer to
such shapes, and two functions, `Circle` and `Rectangle`, which can be such shapes, and two functions, `Circle` and `Rectangle`, which can be
used to construct values of the type (taking arguments of the 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. create a new circle.
Enum variants need not have parameters. This `enum` declaration, 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`: patterns, as in this definition of `area`:
~~~~ ~~~~
use std::float; use std::f64;
# struct Point {x: float, y: float} # struct Point {x: f64, y: f64}
# enum Shape { Circle(Point, float), Rectangle(Point, Point) } # enum Shape { Circle(Point, f64), Rectangle(Point, Point) }
fn area(sh: Shape) -> float { fn area(sh: Shape) -> f64 {
match sh { 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) 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. parentheses.
~~~~ ~~~~
# struct Point { x: float, y: float } # struct Point { x: f64, y: f64 }
# enum Direction { North, East, South, West } # enum Direction { North, East, South, West }
fn point_from_direction(dir: Direction) -> Point { fn point_from_direction(dir: Direction) -> Point {
match dir { match dir {
North => Point { x: 0f, y: 1f }, North => Point { x: 0.0, y: 1.0 },
East => Point { x: 1f, y: 0f }, East => Point { x: 1.0, y: 0.0 },
South => Point { x: 0f, y: -1f }, South => Point { x: 0.0, y: -1.0 },
West => Point { x: -1f, y: 0f } 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: Enum variants may also be structs. For example:
~~~~ ~~~~
use std::float; use std::f64;
# struct Point { x: float, y: float } # struct Point { x: f64, y: f64 }
# fn square(x: float) -> float { x * x } # fn square(x: f64) -> f64 { x * x }
enum Shape { enum Shape {
Circle { center: Point, radius: float }, Circle { center: Point, radius: f64 },
Rectangle { top_left: Point, bottom_right: Point } Rectangle { top_left: Point, bottom_right: Point }
} }
fn area(sh: Shape) -> float { fn area(sh: Shape) -> f64 {
match sh { 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 } => { Rectangle { top_left: top_left, bottom_right: bottom_right } => {
(bottom_right.x - top_left.x) * (top_left.y - bottom_right.y) (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). 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 { match mytup {
(a, b, c) => info2!("{}", a + b + (c as int)) (a, b, c) => info2!("{}", a + b + (c as int))
} }
@ -769,7 +769,7 @@ names.
For example: For example:
~~~~ ~~~~
struct MyTup(int, int, float); struct MyTup(int, int, f64);
let mytup: MyTup = MyTup(10, 20, 30.0); let mytup: MyTup = MyTup(10, 20, 30.0);
match mytup { match mytup {
MyTup(a, b, c) => info2!("{}", a + b + (c as int)) 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. 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 # Destructors
@ -1074,8 +1074,8 @@ As an example, consider a simple struct type, `Point`:
~~~ ~~~
struct Point { struct Point {
x: float, x: f64,
y: float 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: 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 on_the_stack : Point = Point { x: 3.0, y: 4.0 };
let managed_box : @Point = @Point { x: 5.0, y: 1.0 }; let managed_box : @Point = @Point { x: 5.0, y: 1.0 };
let owned_box : ~Point = ~Point { x: 7.0, y: 9.0 }; let owned_box : ~Point = ~Point { x: 7.0, y: 9.0 };
@ -1101,9 +1101,9 @@ bad, but often copies are expensive. So wed like to define a function
that takes the points by pointer. We can use borrowed pointers to do this: that takes the points by pointer. We can use borrowed pointers to do this:
~~~ ~~~
# struct Point { x: float, y: float } # struct Point { x: f64, y: f64 }
# fn sqrt(f: float) -> float { 0f } # fn sqrt(f: f64) -> f64 { 0.0 }
fn compute_distance(p1: &Point, p2: &Point) -> float { fn compute_distance(p1: &Point, p2: &Point) -> f64 {
let x_d = p1.x - p2.x; let x_d = p1.x - p2.x;
let y_d = p1.y - p2.y; let y_d = p1.y - p2.y;
sqrt(x_d * x_d + y_d * y_d) 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: 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 on_the_stack : Point = Point { x: 3.0, y: 4.0 };
# let managed_box : @Point = @Point { x: 5.0, y: 1.0 }; # let managed_box : @Point = @Point { x: 5.0, y: 1.0 };
# let owned_box : ~Point = ~Point { x: 7.0, y: 9.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(&on_the_stack, managed_box);
compute_distance(managed_box, owned_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. 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) } # enum Shape { Rectangle(Point, Point) }
# impl Shape { fn area(&self) -> int { 0 } } # impl Shape { fn area(&self) -> int { 0 } }
let start = @Point { x: 10f, y: 20f }; let start = @Point { x: 10.0, y: 20.0 };
let end = ~Point { x: (*start).x + 100f, y: (*start).y + 100f }; let end = ~Point { x: (*start).x + 100.0, y: (*start).y + 100.0 };
let rect = &Rectangle(*start, *end); let rect = &Rectangle(*start, *end);
let area = (*rect).area(); 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. 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) } # enum Shape { Rectangle(Point, Point) }
# impl Shape { fn area(&self) -> int { 0 } } # impl Shape { fn area(&self) -> int { 0 } }
let start = @Point { x: 10f, y: 20f }; let start = @Point { x: 10.0, y: 20.0 };
let end = ~Point { x: start.x + 100f, y: start.y + 100f }; let end = ~Point { x: start.x + 100.0, y: start.y + 100.0 };
let rect = &Rectangle(*start, *end); let rect = &Rectangle(*start, *end);
let area = rect.area(); let area = rect.area();
~~~ ~~~
@ -1239,8 +1239,8 @@ automatically. For example, if you feel inclined, you could write
something silly like something silly like
~~~ ~~~
# struct Point { x: float, y: float } # struct Point { x: f64, y: f64 }
let point = &@~Point { x: 10f, y: 20f }; let point = &@~Point { x: 10.0, y: 20.0 };
println!("{:f}", point.x); 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. 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) { } # fn draw_rectangle(p: Point, p: Point) { }
struct Point { struct Point {
x: float, x: f64,
y: float y: f64
} }
enum Shape { enum Shape {
Circle(Point, float), Circle(Point, f64),
Rectangle(Point, Point) 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(); 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. 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) { } # fn draw_rectangle(p: Point, p: Point) { }
# struct Point { x: float, y: float } # struct Point { x: f64, y: f64 }
# enum Shape { # enum Shape {
# Circle(Point, float), # Circle(Point, f64),
# Rectangle(Point, Point) # Rectangle(Point, Point)
# } # }
impl Shape { impl Shape {
@ -1650,7 +1650,7 @@ impl Shape {
fn draw_value(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);
(@s).draw_managed(); (@s).draw_managed();
(~s).draw_owned(); (~s).draw_owned();
@ -1663,11 +1663,11 @@ so the compiler will go to great lengths to convert a callee
to a borrowed pointer. 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) { } # fn draw_rectangle(p: Point, p: Point) { }
# struct Point { x: float, y: float } # struct Point { x: f64, y: f64 }
# enum Shape { # enum Shape {
# Circle(Point, float), # Circle(Point, f64),
# Rectangle(Point, Point) # Rectangle(Point, Point)
# } # }
# impl Shape { # impl Shape {
@ -1676,7 +1676,7 @@ to a borrowed pointer.
# fn draw_owned(~self) { ... } # fn draw_owned(~self) { ... }
# fn draw_value(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 // As with typical function arguments, managed and owned pointers
// are automatically converted to borrowed pointers // are automatically converted to borrowed pointers
@ -1700,18 +1700,18 @@ These methods are the preferred way to define constructor functions.
~~~~ {.xfail-test} ~~~~ {.xfail-test}
impl Circle { impl Circle {
fn area(&self) -> float { ... } fn area(&self) -> f64 { ... }
fn new(area: float) -> Circle { ... } fn new(area: f64) -> Circle { ... }
} }
~~~~ ~~~~
To call such a method, just prefix it with the type name and a double colon: To call such a method, just prefix it with the type name and a double colon:
~~~~ ~~~~
use std::float::consts::pi; use std::f64::consts::pi;
struct Circle { radius: float } struct Circle { radius: f64 }
impl Circle { 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); 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<T>` instead of `T`. a function that returns `Option<T>` instead of `T`.
~~~~ ~~~~
# struct Point { x: float, y: float } # struct Point { x: f64, y: f64 }
# enum Shape { Circle(Point, float), Rectangle(Point, Point) } # enum Shape { Circle(Point, f64), Rectangle(Point, Point) }
fn radius(shape: Shape) -> Option<float> { fn radius(shape: Shape) -> Option<f64> {
match shape { match shape {
Circle(_, radius) => Some(radius), Circle(_, radius) => Some(radius),
Rectangle(*) => None Rectangle(*) => None
@ -1986,16 +1986,16 @@ name and a double colon. The compiler uses type inference to decide which
implementation to use. implementation to use.
~~~~ ~~~~
use std::float::consts::pi; use std::f64::consts::pi;
trait Shape { fn new(area: float) -> Self; } trait Shape { fn new(area: f64) -> Self; }
struct Circle { radius: float } struct Circle { radius: f64 }
struct Square { length: float } struct Square { length: f64 }
impl Shape for Circle { 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 { 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; let area = 42.5;
@ -2159,24 +2159,24 @@ For example,
we can define a `Circle` trait that inherits from `Shape`. we can define a `Circle` trait that inherits from `Shape`.
~~~~ ~~~~
trait Shape { fn area(&self) -> float; } trait Shape { fn area(&self) -> f64; }
trait Circle : Shape { fn radius(&self) -> float; } trait Circle : Shape { fn radius(&self) -> f64; }
~~~~ ~~~~
Now, we can implement `Circle` on a type only if we also implement `Shape`. Now, we can implement `Circle` on a type only if we also implement `Shape`.
~~~~ ~~~~
use std::float::consts::pi; use std::f64::consts::pi;
# trait Shape { fn area(&self) -> float; } # trait Shape { fn area(&self) -> f64; }
# trait Circle : Shape { fn radius(&self) -> float; } # trait Circle : Shape { fn radius(&self) -> f64; }
# struct Point { x: float, y: float } # struct Point { x: f64, y: f64 }
# fn square(x: float) -> float { x * x } # fn square(x: f64) -> f64 { x * x }
struct CircleStruct { center: Point, radius: float } struct CircleStruct { center: Point, radius: f64 }
impl Circle for CircleStruct { impl Circle for CircleStruct {
fn radius(&self) -> float { (self.area() / pi).sqrt() } fn radius(&self) -> f64 { (self.area() / pi).sqrt() }
} }
impl Shape for CircleStruct { 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`: Refering to the previous example of `trait Circle : Shape`:
~~~ ~~~
# trait Shape { fn area(&self) -> float; } # trait Shape { fn area(&self) -> f64; }
# trait Circle : Shape { fn radius(&self) -> float; } # trait Circle : Shape { fn radius(&self) -> f64; }
fn radius_times_area<T: Circle>(c: T) -> float { fn radius_times_area<T: Circle>(c: T) -> f64 {
// `c` is both a Circle and a Shape // `c` is both a Circle and a Shape
c.radius() * c.area() c.radius() * c.area()
} }
@ -2201,13 +2201,13 @@ fn radius_times_area<T: Circle>(c: T) -> float {
Likewise, supertrait methods may also be called on trait objects. Likewise, supertrait methods may also be called on trait objects.
~~~ {.xfail-test} ~~~ {.xfail-test}
use std::float::consts::pi; use std::f64::consts::pi;
# trait Shape { fn area(&self) -> float; } # trait Shape { fn area(&self) -> f64; }
# trait Circle : Shape { fn radius(&self) -> float; } # trait Circle : Shape { fn radius(&self) -> f64; }
# struct Point { x: float, y: float } # struct Point { x: f64, y: f64 }
# struct CircleStruct { center: Point, radius: float } # struct CircleStruct { center: Point, radius: f64 }
# impl Circle for CircleStruct { fn radius(&self) -> float { (self.area() / pi).sqrt() } } # impl Circle for CircleStruct { fn radius(&self) -> f64 { (self.area() / pi).sqrt() } }
# impl Shape for CircleStruct { fn area(&self) -> float { pi * square(self.radius) } } # impl Shape for CircleStruct { fn area(&self) -> f64 { pi * square(self.radius) } }
let concrete = @CircleStruct{center:Point{x:3f,y:4f},radius:5f}; let concrete = @CircleStruct{center:Point{x:3f,y:4f},radius:5f};
let mycircle: @Circle = concrete as @Circle; let mycircle: @Circle = concrete as @Circle;
@ -2227,7 +2227,7 @@ of type `ABC` can be randomly generated and converted to a string:
~~~ ~~~
#[deriving(Eq)] #[deriving(Eq)]
struct Circle { radius: float } struct Circle { radius: f64 }
#[deriving(Rand, ToStr)] #[deriving(Rand, ToStr)]
enum ABC { A, B, C } enum ABC { A, B, C }

View file

@ -422,10 +422,6 @@ pub mod reader {
let bits = doc_as_u32(self.next_doc(EsF32)); let bits = doc_as_u32(self.next_doc(EsF32));
unsafe { transmute(bits) } unsafe { transmute(bits) }
} }
fn read_float(&mut self) -> float {
let bits = doc_as_u64(self.next_doc(EsFloat));
(unsafe { transmute::<u64, f64>(bits) }) as float
}
fn read_char(&mut self) -> char { fn read_char(&mut self) -> char {
char::from_u32(doc_as_u32(self.next_doc(EsChar))).unwrap() char::from_u32(doc_as_u32(self.next_doc(EsChar))).unwrap()
} }
@ -839,11 +835,6 @@ pub mod writer {
let bits = unsafe { cast::transmute(v) }; let bits = unsafe { cast::transmute(v) };
self.wr_tagged_u32(EsF32 as uint, bits); 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) { fn emit_char(&mut self, v: char) {
self.wr_tagged_u32(EsChar as uint, v as u32); self.wr_tagged_u32(EsChar as uint, v as u32);
} }

View file

@ -127,7 +127,7 @@ mod tests {
let out = inflate_bytes(cmp); let out = inflate_bytes(cmp);
debug2!("{} bytes deflated to {} ({:.1f}% size)", debug2!("{} bytes deflated to {} ({:.1f}% size)",
input.len(), cmp.len(), 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); assert_eq!(input, out);
} }
} }

View file

@ -18,10 +18,11 @@
use std::char; use std::char;
use std::cast::transmute; use std::cast::transmute;
use std::float; use std::f64;
use std::hashmap::HashMap; use std::hashmap::HashMap;
use std::io::WriterUtil; use std::io::WriterUtil;
use std::io; use std::io;
use std::num;
use std::str; use std::str;
use std::to_str; use std::to_str;
@ -32,7 +33,7 @@ use treemap::TreeMap;
/// Represents a json value /// Represents a json value
#[deriving(Clone, Eq)] #[deriving(Clone, Eq)]
pub enum Json { pub enum Json {
Number(float), Number(f64),
String(~str), String(~str),
Boolean(bool), Boolean(bool),
List(List), List(List),
@ -99,17 +100,17 @@ pub fn Encoder(wr: @io::Writer) -> Encoder {
impl serialize::Encoder for Encoder { impl serialize::Encoder for Encoder {
fn emit_nil(&mut self) { self.wr.write_str("null") } 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_uint(&mut self, v: uint) { self.emit_f64(v as f64); }
fn emit_u64(&mut self, v: u64) { self.emit_float(v as float); } fn emit_u64(&mut self, v: u64) { self.emit_f64(v as f64); }
fn emit_u32(&mut self, v: u32) { self.emit_float(v as float); } fn emit_u32(&mut self, v: u32) { self.emit_f64(v as f64); }
fn emit_u16(&mut self, v: u16) { self.emit_float(v as float); } fn emit_u16(&mut self, v: u16) { self.emit_f64(v as f64); }
fn emit_u8(&mut self, v: u8) { self.emit_float(v as float); } 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_int(&mut self, v: int) { self.emit_f64(v as f64); }
fn emit_i64(&mut self, v: i64) { self.emit_float(v as float); } fn emit_i64(&mut self, v: i64) { self.emit_f64(v as f64); }
fn emit_i32(&mut self, v: i32) { self.emit_float(v as float); } fn emit_i32(&mut self, v: i32) { self.emit_f64(v as f64); }
fn emit_i16(&mut self, v: i16) { self.emit_float(v as float); } fn emit_i16(&mut self, v: i16) { self.emit_f64(v as f64); }
fn emit_i8(&mut self, v: i8) { self.emit_float(v as float); } fn emit_i8(&mut self, v: i8) { self.emit_f64(v as f64); }
fn emit_bool(&mut self, v: bool) { fn emit_bool(&mut self, v: bool) {
if v { 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_f64(&mut self, v: f64) { self.wr.write_str(f64::to_str_digits(v, 6u)) }
fn emit_f32(&mut self, v: f32) { self.emit_float(v as float); } fn emit_f32(&mut self, v: f32) { self.emit_f64(v as f64); }
fn emit_float(&mut self, v: float) {
self.wr.write_str(float::to_str_digits(v, 6u));
}
fn emit_char(&mut self, v: char) { self.emit_str(str::from_char(v)) } 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)) } 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 { impl serialize::Encoder for PrettyEncoder {
fn emit_nil(&mut self) { self.wr.write_str("null") } 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_uint(&mut self, v: uint) { self.emit_f64(v as f64); }
fn emit_u64(&mut self, v: u64) { self.emit_float(v as float); } fn emit_u64(&mut self, v: u64) { self.emit_f64(v as f64); }
fn emit_u32(&mut self, v: u32) { self.emit_float(v as float); } fn emit_u32(&mut self, v: u32) { self.emit_f64(v as f64); }
fn emit_u16(&mut self, v: u16) { self.emit_float(v as float); } fn emit_u16(&mut self, v: u16) { self.emit_f64(v as f64); }
fn emit_u8(&mut self, v: u8) { self.emit_float(v as float); } 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_int(&mut self, v: int) { self.emit_f64(v as f64); }
fn emit_i64(&mut self, v: i64) { self.emit_float(v as float); } fn emit_i64(&mut self, v: i64) { self.emit_f64(v as f64); }
fn emit_i32(&mut self, v: i32) { self.emit_float(v as float); } fn emit_i32(&mut self, v: i32) { self.emit_f64(v as f64); }
fn emit_i16(&mut self, v: i16) { self.emit_float(v as float); } fn emit_i16(&mut self, v: i16) { self.emit_f64(v as f64); }
fn emit_i8(&mut self, v: i8) { self.emit_float(v as float); } fn emit_i8(&mut self, v: i8) { self.emit_f64(v as f64); }
fn emit_bool(&mut self, v: bool) { fn emit_bool(&mut self, v: bool) {
if v { 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_f64(&mut self, v: f64) { self.wr.write_str(f64::to_str_digits(v, 6u)) }
fn emit_f32(&mut self, v: f32) { self.emit_float(v as float); } fn emit_f32(&mut self, v: f32) { self.emit_f64(v as f64); }
fn emit_float(&mut self, v: float) {
self.wr.write_str(float::to_str_digits(v, 6u));
}
fn emit_char(&mut self, v: char) { self.emit_str(str::from_char(v)) } 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)); } fn emit_str(&mut self, v: &str) { self.wr.write_str(escape_str(v)); }
@ -585,11 +580,11 @@ impl<T : Iterator<char>> Parser<T> {
} }
fn parse_number(&mut self) -> Result<Json, Error> { fn parse_number(&mut self) -> Result<Json, Error> {
let mut neg = 1f; let mut neg = 1.0;
if self.ch == '-' { if self.ch == '-' {
self.bump(); self.bump();
neg = -1f; neg = -1.0;
} }
let mut res = match self.parse_integer() { let mut res = match self.parse_integer() {
@ -614,8 +609,8 @@ impl<T : Iterator<char>> Parser<T> {
Ok(Number(neg * res)) Ok(Number(neg * res))
} }
fn parse_integer(&mut self) -> Result<float, Error> { fn parse_integer(&mut self) -> Result<f64, Error> {
let mut res = 0f; let mut res = 0.0;
match self.ch { match self.ch {
'0' => { '0' => {
@ -631,8 +626,8 @@ impl<T : Iterator<char>> Parser<T> {
while !self.eof() { while !self.eof() {
match self.ch { match self.ch {
'0' .. '9' => { '0' .. '9' => {
res *= 10f; res *= 10.0;
res += ((self.ch as int) - ('0' as int)) as float; res += ((self.ch as int) - ('0' as int)) as f64;
self.bump(); self.bump();
} }
@ -646,7 +641,7 @@ impl<T : Iterator<char>> Parser<T> {
Ok(res) Ok(res)
} }
fn parse_decimal(&mut self, res: float) -> Result<float, Error> { fn parse_decimal(&mut self, res: f64) -> Result<f64, Error> {
self.bump(); self.bump();
// Make sure a digit follows the decimal place. // Make sure a digit follows the decimal place.
@ -656,12 +651,12 @@ impl<T : Iterator<char>> Parser<T> {
} }
let mut res = res; let mut res = res;
let mut dec = 1f; let mut dec = 1.0;
while !self.eof() { while !self.eof() {
match self.ch { match self.ch {
'0' .. '9' => { '0' .. '9' => {
dec /= 10f; dec /= 10.0;
res += (((self.ch as int) - ('0' as int)) as float) * dec; res += (((self.ch as int) - ('0' as int)) as f64) * dec;
self.bump(); self.bump();
} }
@ -672,7 +667,7 @@ impl<T : Iterator<char>> Parser<T> {
Ok(res) Ok(res)
} }
fn parse_exponent(&mut self, mut res: float) -> Result<float, Error> { fn parse_exponent(&mut self, mut res: f64) -> Result<f64, Error> {
self.bump(); self.bump();
let mut exp = 0u; let mut exp = 0u;
@ -702,7 +697,7 @@ impl<T : Iterator<char>> Parser<T> {
} }
} }
let exp = float::pow_with_uint(10u, exp); let exp: f64 = num::pow_with_uint(10u, exp);
if neg_exp { if neg_exp {
res /= exp; res /= exp;
} else { } else {
@ -892,17 +887,17 @@ impl serialize::Decoder for Decoder {
} }
} }
fn read_u64(&mut self) -> u64 { self.read_float() as u64 } fn read_u64(&mut self) -> u64 { self.read_f64() as u64 }
fn read_u32(&mut self) -> u32 { self.read_float() as u32 } fn read_u32(&mut self) -> u32 { self.read_f64() as u32 }
fn read_u16(&mut self) -> u16 { self.read_float() as u16 } fn read_u16(&mut self) -> u16 { self.read_f64() as u16 }
fn read_u8 (&mut self) -> u8 { self.read_float() as u8 } fn read_u8 (&mut self) -> u8 { self.read_f64() as u8 }
fn read_uint(&mut self) -> uint { self.read_float() as uint } fn read_uint(&mut self) -> uint { self.read_f64() as uint }
fn read_i64(&mut self) -> i64 { self.read_float() as i64 } fn read_i64(&mut self) -> i64 { self.read_f64() as i64 }
fn read_i32(&mut self) -> i32 { self.read_float() as i32 } fn read_i32(&mut self) -> i32 { self.read_f64() as i32 }
fn read_i16(&mut self) -> i16 { self.read_float() as i16 } fn read_i16(&mut self) -> i16 { self.read_f64() as i16 }
fn read_i8 (&mut self) -> i8 { self.read_float() as i8 } fn read_i8 (&mut self) -> i8 { self.read_f64() as i8 }
fn read_int(&mut self) -> int { self.read_float() as int } fn read_int(&mut self) -> int { self.read_f64() as int }
fn read_bool(&mut self) -> bool { fn read_bool(&mut self) -> bool {
debug2!("read_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_f64(&mut self) -> f64 {
fn read_f32(&mut self) -> f32 { self.read_float() as f32 } debug2!("read_f64");
fn read_float(&mut self) -> float {
debug2!("read_float");
match self.stack.pop() { match self.stack.pop() {
Number(f) => f, Number(f) => f,
value => fail2!("not a number: {:?}", value) 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 { fn read_char(&mut self) -> char {
let mut v = ~[]; let mut v = ~[];
@ -1192,55 +1187,51 @@ impl ToJson for @Json {
} }
impl ToJson for int { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { impl ToJson for u64 {
fn to_json(&self) -> Json { Number(*self as float) } fn to_json(&self) -> Json { Number(*self as f64) }
}
impl ToJson for float {
fn to_json(&self) -> Json { Number(*self) }
} }
impl ToJson for f32 { 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 { impl ToJson for f64 {
fn to_json(&self) -> Json { Number(*self as float) } fn to_json(&self) -> Json { Number(*self) }
} }
impl ToJson for () { impl ToJson for () {
@ -1374,17 +1365,17 @@ mod tests {
#[test] #[test]
fn test_write_number() { fn test_write_number() {
assert_eq!(Number(3f).to_str(), ~"3"); assert_eq!(Number(3.0).to_str(), ~"3");
assert_eq!(Number(3f).to_pretty_str(), ~"3"); assert_eq!(Number(3.0).to_pretty_str(), ~"3");
assert_eq!(Number(3.1f).to_str(), ~"3.1"); assert_eq!(Number(3.1).to_str(), ~"3.1");
assert_eq!(Number(3.1f).to_pretty_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.5).to_str(), ~"-1.5");
assert_eq!(Number(-1.5f).to_pretty_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.5).to_str(), ~"0.5");
assert_eq!(Number(0.5f).to_pretty_str(), ~"0.5"); assert_eq!(Number(0.5).to_pretty_str(), ~"0.5");
} }
#[test] #[test]
@ -1422,7 +1413,7 @@ mod tests {
let longTestList = List(~[ let longTestList = List(~[
Boolean(false), Boolean(false),
Null, Null,
List(~[String(~"foo\nbar"), Number(3.5f)])]); List(~[String(~"foo\nbar"), Number(3.5)])]);
assert_eq!(longTestList.to_str(), assert_eq!(longTestList.to_str(),
~"[false,null,[\"foo\\nbar\",3.5]]"); ~"[false,null,[\"foo\\nbar\",3.5]]");
@ -1649,45 +1640,45 @@ mod tests {
assert_eq!(from_str("1e+"), assert_eq!(from_str("1e+"),
Err(Error {line: 1u, col: 4u, msg: @~"invalid number"})); Err(Error {line: 1u, col: 4u, msg: @~"invalid number"}));
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.1f))); assert_eq!(from_str("3.1"), Ok(Number(3.1)));
assert_eq!(from_str("-1.2"), Ok(Number(-1.2f))); assert_eq!(from_str("-1.2"), Ok(Number(-1.2)));
assert_eq!(from_str("0.4"), Ok(Number(0.4f))); assert_eq!(from_str("0.4"), Ok(Number(0.4)));
assert_eq!(from_str("0.4e5"), Ok(Number(0.4e5f))); assert_eq!(from_str("0.4e5"), Ok(Number(0.4e5)));
assert_eq!(from_str("0.4e+15"), Ok(Number(0.4e15f))); assert_eq!(from_str("0.4e+15"), Ok(Number(0.4e15)));
assert_eq!(from_str("0.4e-01"), Ok(Number(0.4e-01f))); assert_eq!(from_str("0.4e-01"), Ok(Number(0.4e-01)));
assert_eq!(from_str(" 3 "), Ok(Number(3f))); assert_eq!(from_str(" 3 "), Ok(Number(3.0)));
} }
#[test] #[test]
fn test_decode_numbers() { fn test_decode_numbers() {
let mut decoder = Decoder(from_str("3").unwrap()); let mut decoder = Decoder(from_str("3").unwrap());
let v: float = Decodable::decode(&mut decoder); let v: f64 = Decodable::decode(&mut decoder);
assert_eq!(v, 3f); assert_eq!(v, 3.0);
let mut decoder = Decoder(from_str("3.1").unwrap()); let mut decoder = Decoder(from_str("3.1").unwrap());
let v: float = Decodable::decode(&mut decoder); let v: f64 = Decodable::decode(&mut decoder);
assert_eq!(v, 3.1f); assert_eq!(v, 3.1);
let mut decoder = Decoder(from_str("-1.2").unwrap()); let mut decoder = Decoder(from_str("-1.2").unwrap());
let v: float = Decodable::decode(&mut decoder); let v: f64 = Decodable::decode(&mut decoder);
assert_eq!(v, -1.2f); assert_eq!(v, -1.2);
let mut decoder = Decoder(from_str("0.4").unwrap()); let mut decoder = Decoder(from_str("0.4").unwrap());
let v: float = Decodable::decode(&mut decoder); let v: f64 = Decodable::decode(&mut decoder);
assert_eq!(v, 0.4f); assert_eq!(v, 0.4);
let mut decoder = Decoder(from_str("0.4e5").unwrap()); let mut decoder = Decoder(from_str("0.4e5").unwrap());
let v: float = Decodable::decode(&mut decoder); let v: f64 = Decodable::decode(&mut decoder);
assert_eq!(v, 0.4e5f); assert_eq!(v, 0.4e5);
let mut decoder = Decoder(from_str("0.4e15").unwrap()); let mut decoder = Decoder(from_str("0.4e15").unwrap());
let v: float = Decodable::decode(&mut decoder); let v: f64 = Decodable::decode(&mut decoder);
assert_eq!(v, 0.4e15f); assert_eq!(v, 0.4e15);
let mut decoder = Decoder(from_str("0.4e-01").unwrap()); let mut decoder = Decoder(from_str("0.4e-01").unwrap());
let v: float = Decodable::decode(&mut decoder); let v: f64 = Decodable::decode(&mut decoder);
assert_eq!(v, 0.4e-01f); assert_eq!(v, 0.4e-01);
} }
#[test] #[test]
@ -1769,11 +1760,11 @@ mod tests {
assert_eq!(from_str("[ false ]"), Ok(List(~[Boolean(false)]))); assert_eq!(from_str("[ false ]"), Ok(List(~[Boolean(false)])));
assert_eq!(from_str("[null]"), Ok(List(~[Null]))); assert_eq!(from_str("[null]"), Ok(List(~[Null])));
assert_eq!(from_str("[3, 1]"), 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"), 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]]"), 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] #[test]
@ -1855,7 +1846,7 @@ mod tests {
assert_eq!(from_str("{}").unwrap(), mk_object([])); assert_eq!(from_str("{}").unwrap(), mk_object([]));
assert_eq!(from_str("{\"a\": 3}").unwrap(), assert_eq!(from_str("{\"a\": 3}").unwrap(),
mk_object([(~"a", Number(3.0f))])); mk_object([(~"a", Number(3.0))]));
assert_eq!(from_str( assert_eq!(from_str(
"{ \"a\": null, \"b\" : true }").unwrap(), "{ \"a\": null, \"b\" : true }").unwrap(),
@ -1882,7 +1873,7 @@ mod tests {
"]" + "]" +
"}").unwrap(), "}").unwrap(),
mk_object([ mk_object([
(~"a", Number(1.0f)), (~"a", Number(1.0)),
(~"b", List(~[ (~"b", List(~[
Boolean(true), Boolean(true),
String(~"foo\nbar"), String(~"foo\nbar"),

View file

@ -30,7 +30,6 @@ pub struct Cmplx<T> {
im: T im: T
} }
pub type Complex = Cmplx<float>;
pub type Complex32 = Cmplx<f32>; pub type Complex32 = Cmplx<f32>;
pub type Complex64 = Cmplx<f64>; pub type Complex64 = Cmplx<f64>;
@ -196,25 +195,25 @@ mod test {
use super::*; use super::*;
use std::num::{Zero,One,Real}; use std::num::{Zero,One,Real};
pub static _0_0i : Complex = Cmplx { re: 0f, im: 0f }; pub static _0_0i : Complex64 = Cmplx { re: 0.0, im: 0.0 };
pub static _1_0i : Complex = Cmplx { re: 1f, im: 0f }; pub static _1_0i : Complex64 = Cmplx { re: 1.0, im: 0.0 };
pub static _1_1i : Complex = Cmplx { re: 1f, im: 1f }; pub static _1_1i : Complex64 = Cmplx { re: 1.0, im: 1.0 };
pub static _0_1i : Complex = Cmplx { re: 0f, im: 1f }; pub static _0_1i : Complex64 = Cmplx { re: 0.0, im: 1.0 };
pub static _neg1_1i : Complex = Cmplx { re: -1f, im: 1f }; pub static _neg1_1i : Complex64 = Cmplx { re: -1.0, im: 1.0 };
pub static _05_05i : Complex = Cmplx { re: 0.5f, im: 0.5f }; pub static _05_05i : Complex64 = Cmplx { re: 0.5, im: 0.5 };
pub static all_consts : [Complex, .. 5] = [_0_0i, _1_0i, _1_1i, _neg1_1i, _05_05i]; pub static all_consts : [Complex64, .. 5] = [_0_0i, _1_0i, _1_1i, _neg1_1i, _05_05i];
#[test] #[test]
fn test_consts() { fn test_consts() {
// check our constants are what Cmplx::new creates // 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)); assert_eq!(c, Cmplx::new(r,i));
} }
test(_0_0i, 0f, 0f); test(_0_0i, 0.0, 0.0);
test(_1_0i, 1f, 0f); test(_1_0i, 1.0, 0.0);
test(_1_1i, 1f, 1f); test(_1_1i, 1.0, 1.0);
test(_neg1_1i, -1f, 1f); test(_neg1_1i, -1.0, 1.0);
test(_05_05i, 0.5f, 0.5f); test(_05_05i, 0.5, 0.5);
assert_eq!(_0_0i, Zero::zero()); assert_eq!(_0_0i, Zero::zero());
assert_eq!(_1_0i, One::one()); assert_eq!(_1_0i, One::one());
@ -224,23 +223,23 @@ mod test {
#[ignore(cfg(target_arch = "x86"))] #[ignore(cfg(target_arch = "x86"))]
// FIXME #7158: (maybe?) currently failing on x86. // FIXME #7158: (maybe?) currently failing on x86.
fn test_norm() { 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_sqr(), ns);
assert_eq!(c.norm(), ns.sqrt()) assert_eq!(c.norm(), ns.sqrt())
} }
test(_0_0i, 0f); test(_0_0i, 0.0);
test(_1_0i, 1f); test(_1_0i, 1.0);
test(_1_1i, 2f); test(_1_1i, 2.0);
test(_neg1_1i, 2f); test(_neg1_1i, 2.0);
test(_05_05i, 0.5f); test(_05_05i, 0.5);
} }
#[test] #[test]
fn test_scale_unscale() { fn test_scale_unscale() {
assert_eq!(_05_05i.scale(2f), _1_1i); assert_eq!(_05_05i.scale(2.0), _1_1i);
assert_eq!(_1_1i.unscale(2f), _05_05i); assert_eq!(_1_1i.unscale(2.0), _05_05i);
for &c in all_consts.iter() { 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] #[test]
fn test_arg() { fn test_arg() {
fn test(c: Complex, arg: float) { fn test(c: Complex64, arg: f64) {
assert!(c.arg().approx_eq(&arg)) assert!(c.arg().approx_eq(&arg))
} }
test(_1_0i, 0f); test(_1_0i, 0.0);
test(_1_1i, 0.25f * Real::pi()); test(_1_1i, 0.25 * Real::pi());
test(_neg1_1i, 0.75f * Real::pi()); test(_neg1_1i, 0.75 * Real::pi());
test(_05_05i, 0.25f * Real::pi()); test(_05_05i, 0.25 * Real::pi());
} }
#[test] #[test]
fn test_polar_conv() { fn test_polar_conv() {
fn test(c: Complex) { fn test(c: Complex64) {
let (r, theta) = c.to_polar(); let (r, theta) = c.to_polar();
assert!((c - Cmplx::from_polar(&r, &theta)).norm() < 1e-6); assert!((c - Cmplx::from_polar(&r, &theta)).norm() < 1e-6);
} }
@ -316,7 +315,7 @@ mod test {
#[test] #[test]
fn test_mul() { 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); assert_eq!(_1_1i * _0_1i, _neg1_1i);
// i^2 & i^4 // i^2 & i^4
@ -349,7 +348,7 @@ mod test {
#[test] #[test]
fn test_to_str() { fn test_to_str() {
fn test(c : Complex, s: ~str) { fn test(c : Complex64, s: ~str) {
assert_eq!(c.to_str(), s); assert_eq!(c.to_str(), s);
} }
test(_0_0i, ~"0+0i"); test(_0_0i, ~"0+0i");

View file

@ -41,7 +41,6 @@ pub trait Encoder {
fn emit_i16(&mut self, v: i16); fn emit_i16(&mut self, v: i16);
fn emit_i8(&mut self, v: i8); fn emit_i8(&mut self, v: i8);
fn emit_bool(&mut self, v: bool); fn emit_bool(&mut self, v: bool);
fn emit_float(&mut self, v: float);
fn emit_f64(&mut self, v: f64); fn emit_f64(&mut self, v: f64);
fn emit_f32(&mut self, v: f32); fn emit_f32(&mut self, v: f32);
fn emit_char(&mut self, v: char); fn emit_char(&mut self, v: char);
@ -108,7 +107,6 @@ pub trait Decoder {
fn read_bool(&mut self) -> bool; fn read_bool(&mut self) -> bool;
fn read_f64(&mut self) -> f64; fn read_f64(&mut self) -> f64;
fn read_f32(&mut self) -> f32; fn read_f32(&mut self) -> f32;
fn read_float(&mut self) -> float;
fn read_char(&mut self) -> char; fn read_char(&mut self) -> char;
fn read_str(&mut self) -> ~str; fn read_str(&mut self) -> ~str;
@ -326,18 +324,6 @@ impl<D:Decoder> Decodable<D> for @str {
} }
} }
impl<S:Encoder> Encodable<S> for float {
fn encode(&self, s: &mut S) {
s.emit_float(*self)
}
}
impl<D:Decoder> Decodable<D> for float {
fn decode(d: &mut D) -> float {
d.read_float()
}
}
impl<S:Encoder> Encodable<S> for f32 { impl<S:Encoder> Encodable<S> for f32 {
fn encode(&self, s: &mut S) { fn encode(&self, s: &mut S) {
s.emit_f32(*self) s.emit_f32(*self)

View file

@ -915,13 +915,13 @@ mod test_tim_sort {
#[deriving(Clone)] #[deriving(Clone)]
struct CVal { struct CVal {
val: float, val: f64,
} }
impl Ord for CVal { impl Ord for CVal {
fn lt(&self, other: &CVal) -> bool { fn lt(&self, other: &CVal) -> bool {
let mut rng = rand::rng(); let mut rng = rand::rng();
if rng.gen::<float>() > 0.995 { if rng.gen::<f64>() > 0.995 {
fail2!("It's happening!!!"); fail2!("It's happening!!!");
} }
(*self).val < other.val (*self).val < other.val
@ -1054,7 +1054,7 @@ mod big_tests {
for i in range(lo, hi) { for i in range(lo, hi) {
let n = 1 << i; 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() rng.gen()
}; };
@ -1106,7 +1106,7 @@ mod big_tests {
isSorted(arr); isSorted(arr);
let half = n / 2; 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 tim_sort(arr); // !sort
isSorted(arr); isSorted(arr);
} }
@ -1125,7 +1125,7 @@ mod big_tests {
for i in range(lo, hi) { for i in range(lo, hi) {
let n = 1 << i; let n = 1 << i;
let arr: ~[@float] = do vec::from_fn(n) |_i| { let arr: ~[@f64] = do vec::from_fn(n) |_i| {
@rng.gen() @rng.gen()
}; };
let mut arr = arr; let mut arr = arr;
@ -1178,7 +1178,7 @@ mod big_tests {
isSorted(arr); isSorted(arr);
let half = n / 2; 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 tim_sort(arr); // !sort
isSorted(arr); isSorted(arr);
} }

View file

@ -485,14 +485,14 @@ impl ConsoleTestState {
self.out.write_str(*k); self.out.write_str(*k);
self.out.write_str(": "); self.out.write_str(": ");
self.write_improved(); 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) => { Regression(pct) => {
regressed += 1; regressed += 1;
self.out.write_str(*k); self.out.write_str(*k);
self.out.write_str(": "); self.out.write_str(": ");
self.write_regressed(); 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 => (), None => (),
Some(pct) => Some(pct) =>
self.out.write_str(format!("with noise-tolerance forced to: {}%%\n", 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); let (diff, ok) = self.metrics.ratchet(pth, ratchet_pct);
self.write_metric_diff(&diff); self.write_metric_diff(&diff);
@ -551,8 +551,8 @@ pub fn fmt_metrics(mm: &MetricMap) -> ~str {
let v : ~[~str] = mm.iter() let v : ~[~str] = mm.iter()
.map(|(k,v)| format!("{}: {} (+/- {})", .map(|(k,v)| format!("{}: {} (+/- {})",
*k, *k,
v.value as float, v.value as f64,
v.noise as float)) v.noise as f64))
.collect(); .collect();
v.connect(", ") v.connect(", ")
} }
@ -878,8 +878,8 @@ fn calc_result(desc: &TestDesc, task_succeeded: bool) -> TestResult {
impl ToJson for Metric { impl ToJson for Metric {
fn to_json(&self) -> json::Json { fn to_json(&self) -> json::Json {
let mut map = ~TreeMap::new(); let mut map = ~TreeMap::new();
map.insert(~"value", json::Number(self.value as float)); map.insert(~"value", json::Number(self.value as f64));
map.insert(~"noise", json::Number(self.noise as float)); map.insert(~"noise", json::Number(self.noise as f64));
json::Object(map) json::Object(map)
} }
} }
@ -1083,9 +1083,9 @@ impl BenchHarness {
debug2!("{} samples, median {}, MAD={}, MADP={}", debug2!("{} samples, median {}, MAD={}, MADP={}",
samples.len(), samples.len(),
summ.median as float, summ.median as f64,
summ.median_abs_dev as float, summ.median_abs_dev as f64,
summ.median_abs_dev_pct as float); summ.median_abs_dev_pct as f64);
let now = precise_time_ns(); let now = precise_time_ns();
let loop_run = now - loop_start; let loop_run = now - loop_start;

View file

@ -92,8 +92,8 @@ pub fn precise_time_ns() -> u64 {
* Returns the current value of a high-resolution performance counter * Returns the current value of a high-resolution performance counter
* in seconds since an unspecified epoch. * in seconds since an unspecified epoch.
*/ */
pub fn precise_time_s() -> float { pub fn precise_time_s() -> f64 {
return (precise_time_ns() as float) / 1000000000.; return (precise_time_ns() as f64) / 1000000000.;
} }
pub fn tzset() { pub fn tzset() {
@ -905,7 +905,7 @@ fn do_strftime(format: &str, tm: &Tm) -> ~str {
mod tests { mod tests {
use super::*; use super::*;
use std::float; use std::f64;
use std::os; use std::os;
use std::result::{Err, Ok}; use std::result::{Err, Ok};
@ -934,7 +934,7 @@ mod tests {
let s0 = precise_time_s(); let s0 = precise_time_s();
let ns1 = precise_time_ns(); 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.); assert!(s0 > 0.);
let ns0 = (s0 * 1000000000.) as u64; let ns0 = (s0 * 1000000000.) as u64;
debug2!("ns0={:?} ns", ns0); debug2!("ns0={:?} ns", ns0);

View file

@ -603,11 +603,11 @@ pub fn build_target_config(sopts: @session::options,
None => early_error(demitter, None => early_error(demitter,
~"unknown architecture: " + sopts.target_triple) ~"unknown architecture: " + sopts.target_triple)
}; };
let (int_type, uint_type, float_type) = match arch { let (int_type, uint_type) = match arch {
abi::X86 => (ast::ty_i32, ast::ty_u32, ast::ty_f64), abi::X86 => (ast::ty_i32, ast::ty_u32),
abi::X86_64 => (ast::ty_i64, ast::ty_u64, ast::ty_f64), abi::X86_64 => (ast::ty_i64, ast::ty_u64),
abi::Arm => (ast::ty_i32, ast::ty_u32, ast::ty_f64), abi::Arm => (ast::ty_i32, ast::ty_u32),
abi::Mips => (ast::ty_i32, ast::ty_u32, ast::ty_f64) abi::Mips => (ast::ty_i32, ast::ty_u32)
}; };
let target_triple = sopts.target_triple.clone(); let target_triple = sopts.target_triple.clone();
let target_strs = match arch { let target_strs = match arch {
@ -622,7 +622,6 @@ pub fn build_target_config(sopts: @session::options,
target_strs: target_strs, target_strs: target_strs,
int_type: int_type, int_type: int_type,
uint_type: uint_type, uint_type: uint_type,
float_type: float_type
}; };
return target_cfg; return target_cfg;
} }

View file

@ -19,7 +19,7 @@ use metadata;
use middle::lint; use middle::lint;
use syntax::ast::NodeId; 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::codemap::Span;
use syntax::diagnostic; use syntax::diagnostic;
use syntax::parse::ParseSess; use syntax::parse::ParseSess;
@ -47,7 +47,6 @@ pub struct config {
target_strs: target_strs::t, target_strs: target_strs::t,
int_type: int_ty, int_type: int_ty,
uint_type: uint_ty, uint_type: uint_ty,
float_type: float_ty
} }
pub static verbose: uint = 1 << 0; pub static verbose: uint = 1 << 0;

View file

@ -304,7 +304,6 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
'b' => return ty::mk_bool(), 'b' => return ty::mk_bool(),
'i' => return ty::mk_int(), 'i' => return ty::mk_int(),
'u' => return ty::mk_uint(), 'u' => return ty::mk_uint(),
'l' => return ty::mk_float(),
'M' => { 'M' => {
match next(st) { match next(st) {
'b' => return ty::mk_mach_uint(ast::ty_u8), 'b' => return ty::mk_mach_uint(ast::ty_u8),

View file

@ -260,7 +260,6 @@ fn enc_sty(w: @io::Writer, cx: @ctxt, st: &ty::sty) {
} }
ty::ty_float(t) => { ty::ty_float(t) => {
match t { match t {
ty_f => w.write_char('l'),
ty_f32 => w.write_str(&"Mf"), ty_f32 => w.write_str(&"Mf"),
ty_f64 => w.write_str(&"MF"), ty_f64 => w.write_str(&"MF"),
} }

View file

@ -115,9 +115,9 @@ pub fn check_crate(
return (bccx.root_map, bccx.write_guard_map); return (bccx.root_map, bccx.write_guard_map);
fn make_stat(bccx: &mut BorrowckCtxt, stat: uint) -> ~str { fn make_stat(bccx: &mut BorrowckCtxt, stat: uint) -> ~str {
let stat_f = stat as float; let stat_f = stat as f64;
let total = bccx.stats.guaranteed_paths as float; let total = bccx.stats.guaranteed_paths as f64;
format!("{} ({:.0f}%)", stat , stat_f * 100f / total) format!("{} ({:.0f}%)", stat , stat_f * 100.0 / total)
} }
} }

View file

@ -475,9 +475,9 @@ pub fn lit_to_const(lit: &lit) -> const_val {
lit_int(n, _) => const_int(n), lit_int(n, _) => const_int(n),
lit_uint(n, _) => const_uint(n), lit_uint(n, _) => const_uint(n),
lit_int_unsuffixed(n) => const_int(n), lit_int_unsuffixed(n) => const_int(n),
lit_float(n, _) => const_float(from_str::<float>(n).unwrap() as f64), lit_float(n, _) => const_float(from_str::<f64>(n).unwrap() as f64),
lit_float_unsuffixed(n) => lit_float_unsuffixed(n) =>
const_float(from_str::<float>(n).unwrap() as f64), const_float(from_str::<f64>(n).unwrap() as f64),
lit_nil => const_int(0i64), lit_nil => const_int(0i64),
lit_bool(b) => const_bool(b) lit_bool(b) => const_bool(b)
} }

View file

@ -772,7 +772,6 @@ pub fn PrimitiveTypeTable() -> PrimitiveTypeTable {
table.intern("bool", ty_bool); table.intern("bool", ty_bool);
table.intern("char", ty_char); table.intern("char", ty_char);
table.intern("float", ty_float(ty_f));
table.intern("f32", ty_float(ty_f32)); table.intern("f32", ty_float(ty_f32));
table.intern("f64", ty_float(ty_f64)); table.intern("f64", ty_float(ty_f64));
table.intern("int", ty_int(ty_i)); table.intern("int", ty_int(ty_i));

View file

@ -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))) 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) => { ast::lit_float_unsuffixed(fs) => {
let lit_float_ty = ty::node_id_to_type(cx.tcx, e.id); let lit_float_ty = ty::node_id_to_type(cx.tcx, e.id);
match ty::get(lit_float_ty).sty { match ty::get(lit_float_ty).sty {
ty::ty_float(t) => { 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, cx.sess.span_bug(lit.span,

View file

@ -109,7 +109,6 @@ pub struct CrateContext {
upcalls: @upcall::Upcalls, upcalls: @upcall::Upcalls,
tydesc_type: Type, tydesc_type: Type,
int_type: Type, int_type: Type,
float_type: Type,
opaque_vec_type: Type, opaque_vec_type: Type,
builder: BuilderRef_res, builder: BuilderRef_res,
crate_map: ValueRef, crate_map: ValueRef,
@ -156,7 +155,6 @@ impl CrateContext {
base::declare_dbg_intrinsics(llmod, &mut intrinsics); base::declare_dbg_intrinsics(llmod, &mut intrinsics);
} }
let int_type = Type::int(targ_cfg.arch); 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 tydesc_type = Type::tydesc(targ_cfg.arch);
let opaque_vec_type = Type::opaque_vec(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), upcalls: upcall::declare_upcalls(targ_cfg, llmod),
tydesc_type: tydesc_type, tydesc_type: tydesc_type,
int_type: int_type, int_type: int_type,
float_type: float_type,
opaque_vec_type: opaque_vec_type, opaque_vec_type: opaque_vec_type,
builder: BuilderRef_res(llvm::LLVMCreateBuilderInContext(llcx)), builder: BuilderRef_res(llvm::LLVMCreateBuilderInContext(llcx)),
crate_map: crate_map, crate_map: crate_map,

View file

@ -1046,7 +1046,6 @@ fn basic_type_metadata(cx: &mut CrateContext, t: ty::t) -> DIType {
ast::ty_u64 => (~"u64", DW_ATE_unsigned) ast::ty_u64 => (~"u64", DW_ATE_unsigned)
}, },
ty::ty_float(float_ty) => match float_ty { ty::ty_float(float_ty) => match float_ty {
ast::ty_f => (~"float", DW_ATE_float),
ast::ty_f32 => (~"f32", DW_ATE_float), ast::ty_f32 => (~"f32", DW_ATE_float),
ast::ty_f64 => (~"f64", DW_ATE_float) ast::ty_f64 => (~"f64", DW_ATE_float)
}, },

View file

@ -168,7 +168,6 @@ impl Reflector {
ty::ty_uint(ast::ty_u16) => self.leaf("u16"), ty::ty_uint(ast::ty_u16) => self.leaf("u16"),
ty::ty_uint(ast::ty_u32) => self.leaf("u32"), ty::ty_uint(ast::ty_u32) => self.leaf("u32"),
ty::ty_uint(ast::ty_u64) => self.leaf("u64"), 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_f32) => self.leaf("f32"),
ty::ty_float(ast::ty_f64) => self.leaf("f64"), ty::ty_float(ast::ty_f64) => self.leaf("f64"),

View file

@ -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 { match t {
ast::ty_f => ctx.float_type,
ast::ty_f32 => Type::f32(), ast::ty_f32 => Type::f32(),
ast::ty_f64 => Type::f64() ast::ty_f64 => Type::f64()
} }

View file

@ -111,7 +111,7 @@ pub fn sizing_type_of(cx: &mut CrateContext, t: ty::t) -> Type {
ty::ty_char => Type::char(), ty::ty_char => Type::char(),
ty::ty_int(t) => Type::int_from_ty(cx, t), ty::ty_int(t) => Type::int_from_ty(cx, t),
ty::ty_uint(t) => Type::uint_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_uniq) |
ty::ty_estr(ty::vstore_box) | 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_char => Type::char(),
ty::ty_int(t) => Type::int_from_ty(cx, t), ty::ty_int(t) => Type::int_from_ty(cx, t),
ty::ty_uint(t) => Type::uint_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_uniq) => {
Type::vec(cx.sess.targ_cfg.arch, &Type::i8()).ptr_to() Type::vec(cx.sess.targ_cfg.arch, &Type::i8()).ptr_to()
} }

View file

@ -583,7 +583,6 @@ mod primitives {
def_prim_ty!(TY_U16, super::ty_uint(ast::ty_u16), 10) 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_U32, super::ty_uint(ast::ty_u32), 11)
def_prim_ty!(TY_U64, super::ty_uint(ast::ty_u64), 12) 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_F32, super::ty_float(ast::ty_f32), 14)
def_prim_ty!(TY_F64, super::ty_float(ast::ty_f64), 15) 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] #[inline]
pub fn mk_i64() -> t { mk_prim_t(&primitives::TY_I64) } pub fn mk_i64() -> t { mk_prim_t(&primitives::TY_I64) }
#[inline]
pub fn mk_float() -> t { mk_prim_t(&primitives::TY_FLOAT) }
#[inline] #[inline]
pub fn mk_f32() -> t { mk_prim_t(&primitives::TY_F32) } 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 { pub fn mk_mach_float(tm: ast::float_ty) -> t {
match tm { match tm {
ast::ty_f => mk_float(),
ast::ty_f32 => mk_f32(), ast::ty_f32 => mk_f32(),
ast::ty_f64 => mk_f64(), 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 { pub fn type_is_machine(ty: t) -> bool {
match get(ty).sty { 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, ty_int(*) | ty_uint(*) | ty_float(*) => true,
_ => false _ => false
} }

View file

@ -269,9 +269,9 @@ impl ResolveState {
Some(t) => ty::mk_mach_float(t), Some(t) => ty::mk_mach_float(t),
None => { None => {
if self.should(force_fvar) { if self.should(force_fvar) {
// As a last resort, default to float. // As a last resort, default to f64.
let ty = ty::mk_float(); let ty = ty::mk_f64();
self.infcx.set(vid, Root(Some(ast::ty_f), node.rank)); self.infcx.set(vid, Root(Some(ast::ty_f64), node.rank));
ty ty
} else { } else {
ty::mk_float_var(self.infcx.tcx, vid) ty::mk_float_var(self.infcx.tcx, vid)

View file

@ -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_int(t) => ast_util::int_ty_to_str(t),
ty_uint(ast::ty_u) => ~"uint", ty_uint(ast::ty_u) => ~"uint",
ty_uint(t) => ast_util::uint_ty_to_str(t), 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_float(t) => ast_util::float_ty_to_str(t),
ty_box(ref tm) => ~"@" + mt_to_str(cx, tm), ty_box(ref tm) => ~"@" + mt_to_str(cx, tm),
ty_uniq(ref tm) => ~"~" + mt_to_str(cx, tm), ty_uniq(ref tm) => ~"~" + mt_to_str(cx, tm),

View file

@ -233,7 +233,6 @@ impl fmt::Default for clean::Type {
ast::ty_uint(ast::ty_u16) => "u16", ast::ty_uint(ast::ty_u16) => "u16",
ast::ty_uint(ast::ty_u32) => "u32", ast::ty_uint(ast::ty_u32) => "u32",
ast::ty_uint(ast::ty_u64) => "u64", 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_f32) => "f32",
ast::ty_float(ast::ty_f64) => "f64", ast::ty_float(ast::ty_f64) => "f64",
ast::ty_str => "str", ast::ty_str => "str",

View file

@ -89,7 +89,6 @@ clone_impl!(u16)
clone_impl!(u32) clone_impl!(u32)
clone_impl!(u64) clone_impl!(u64)
clone_impl!(float)
clone_impl!(f32) clone_impl!(f32)
clone_impl!(f64) clone_impl!(f64)
@ -169,7 +168,6 @@ deep_clone_impl!(u16)
deep_clone_impl!(u32) deep_clone_impl!(u32)
deep_clone_impl!(u64) deep_clone_impl!(u64)
deep_clone_impl!(float)
deep_clone_impl!(f32) deep_clone_impl!(f32)
deep_clone_impl!(f64) deep_clone_impl!(f64)
@ -241,9 +239,9 @@ fn test_extern_fn_clone() {
trait Empty {} trait Empty {}
impl Empty for int {} impl Empty for int {}
fn test_fn_a() -> float { 1.0 } fn test_fn_a() -> f64 { 1.0 }
fn test_fn_b<T: Empty>(x: T) -> T { x } fn test_fn_b<T: Empty>(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_a.clone();
let _ = test_fn_b::<int>.clone(); let _ = test_fn_b::<int>.clone();

View file

@ -1035,7 +1035,6 @@ macro_rules! floating(($ty:ident) => {
} }
} }
}) })
floating!(float)
floating!(f32) floating!(f32)
floating!(f64) floating!(f64)
@ -1096,7 +1095,6 @@ delegate!(~str to String)
delegate!(&'self str to String) delegate!(&'self str to String)
delegate!(bool to Bool) delegate!(bool to Bool)
delegate!(char to Char) delegate!(char to Char)
delegate!(float to Float)
delegate!(f32 to Float) delegate!(f32 to Float)
delegate!(f64 to Float) delegate!(f64 to Float)

View file

@ -2269,12 +2269,12 @@ mod tests {
#[test] #[test]
fn test_iterator_scan() { fn test_iterator_scan() {
// test the type inference // test the type inference
fn add(old: &mut int, new: &uint) -> Option<float> { fn add(old: &mut int, new: &uint) -> Option<f64> {
*old += *new as int; *old += *new as int;
Some(*old as float) Some(*old as f64)
} }
let xs = [0u, 1, 2, 3, 4]; 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 it = xs.iter().scan(0, add);
let mut i = 0; let mut i = 0;

File diff suppressed because it is too large Load diff

View file

@ -385,7 +385,6 @@ pub trait NumCast {
fn to_f32(&self) -> f32; fn to_f32(&self) -> f32;
fn to_f64(&self) -> f64; fn to_f64(&self) -> f64;
fn to_float(&self) -> float;
} }
macro_rules! impl_num_cast( 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_f32(&self) -> f32 { *self as f32 }
#[inline] fn to_f64(&self) -> f64 { *self as f64 } #[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!(int, to_int)
impl_num_cast!(f32, to_f32) impl_num_cast!(f32, to_f32)
impl_num_cast!(f64, to_f64) impl_num_cast!(f64, to_f64)
impl_num_cast!(float, to_float)
pub trait ToStrRadix { pub trait ToStrRadix {
fn to_str_radix(&self, radix: uint) -> ~str; fn to_str_radix(&self, radix: uint) -> ~str;
@ -579,7 +576,6 @@ mod tests {
assert_eq!(20i16, _20.to_i16()); assert_eq!(20i16, _20.to_i16());
assert_eq!(20i32, _20.to_i32()); assert_eq!(20i32, _20.to_i32());
assert_eq!(20i64, _20.to_i64()); assert_eq!(20i64, _20.to_i64());
assert_eq!(20f, _20.to_float());
assert_eq!(20f32, _20.to_f32()); assert_eq!(20f32, _20.to_f32());
assert_eq!(20f64, _20.to_f64()); assert_eq!(20f64, _20.to_f64());
@ -593,7 +589,6 @@ mod tests {
assert_eq!(_20, NumCast::from(20i16)); assert_eq!(_20, NumCast::from(20i16));
assert_eq!(_20, NumCast::from(20i32)); assert_eq!(_20, NumCast::from(20i32));
assert_eq!(_20, NumCast::from(20i64)); assert_eq!(_20, NumCast::from(20i64));
assert_eq!(_20, NumCast::from(20f));
assert_eq!(_20, NumCast::from(20f32)); assert_eq!(_20, NumCast::from(20f32));
assert_eq!(_20, NumCast::from(20f64)); assert_eq!(_20, NumCast::from(20f64));
@ -607,7 +602,6 @@ mod tests {
assert_eq!(_20, cast(20i16)); assert_eq!(_20, cast(20i16));
assert_eq!(_20, cast(20i32)); assert_eq!(_20, cast(20i32));
assert_eq!(_20, cast(20i64)); assert_eq!(_20, cast(20i64));
assert_eq!(_20, cast(20f));
assert_eq!(_20, cast(20f32)); assert_eq!(_20, cast(20f32));
assert_eq!(_20, cast(20f64)); assert_eq!(_20, cast(20f64));
}) })
@ -625,7 +619,6 @@ mod tests {
#[test] fn test_int_cast() { test_cast_20!(20i) } #[test] fn test_int_cast() { test_cast_20!(20i) }
#[test] fn test_f32_cast() { test_cast_20!(20f32) } #[test] fn test_f32_cast() { test_cast_20!(20f32) }
#[test] fn test_f64_cast() { test_cast_20!(20f64) } #[test] fn test_f64_cast() { test_cast_20!(20f64) }
#[test] fn test_float_cast() { test_cast_20!(20f) }
#[test] #[test]
fn test_saturating_add_uint() { fn test_saturating_add_uint() {

View file

@ -83,7 +83,6 @@ macro_rules! impl_NumStrConv_Integer (($t:ty) => (
// FIXME: #4955 // FIXME: #4955
// Replace by two generic impls for traits 'Integral' and 'Floating' // Replace by two generic impls for traits 'Integral' and 'Floating'
impl_NumStrConv_Floating!(float)
impl_NumStrConv_Floating!(f32) impl_NumStrConv_Floating!(f32)
impl_NumStrConv_Floating!(f64) impl_NumStrConv_Floating!(f64)
@ -735,8 +734,8 @@ mod test {
mod bench { mod bench {
use extra::test::BenchHarness; use extra::test::BenchHarness;
use rand::{XorShiftRng, Rng}; use rand::{XorShiftRng, Rng};
use float;
use to_str::ToStr; use to_str::ToStr;
use f64;
#[bench] #[bench]
fn uint_to_str_rand(bh: &mut BenchHarness) { fn uint_to_str_rand(bh: &mut BenchHarness) {
@ -750,7 +749,7 @@ mod bench {
fn float_to_str_rand(bh: &mut BenchHarness) { fn float_to_str_rand(bh: &mut BenchHarness) {
let mut rng = XorShiftRng::new(); let mut rng = XorShiftRng::new();
do bh.iter { do bh.iter {
float::to_str(rng.gen()); f64::to_str(rng.gen());
} }
} }
} }

View file

@ -14,7 +14,7 @@ Random number generation.
The key functions are `random()` and `Rng::gen()`. These are polymorphic 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 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 means that often a simple call to `rand::random()` or `rng.gen()` will
suffice, but sometimes an annotation is required, e.g. `rand::random::<float>()`. suffice, but sometimes an annotation is required, e.g. `rand::random::<f64>()`.
See the `distributions` submodule for sampling random numbers from See the `distributions` submodule for sampling random numbers from
distributions like normal and exponential. distributions like normal and exponential.
@ -145,13 +145,6 @@ impl Rand for u64 {
} }
} }
impl Rand for float {
#[inline]
fn rand<R: Rng>(rng: &mut R) -> float {
rng.gen::<f64>() as float
}
}
impl Rand for f32 { impl Rand for f32 {
#[inline] #[inline]
fn rand<R: Rng>(rng: &mut R) -> f32 { fn rand<R: Rng>(rng: &mut R) -> f32 {
@ -271,7 +264,7 @@ pub trait Rng {
/// let rng = rand::task_rng(); /// let rng = rand::task_rng();
/// let x: uint = rng.gen(); /// let x: uint = rng.gen();
/// println!("{}", x); /// println!("{}", x);
/// println!("{:?}", rng.gen::<(float, bool)>()); /// println!("{:?}", rng.gen::<(f64, bool)>());
/// } /// }
/// ``` /// ```
#[inline(always)] #[inline(always)]
@ -290,7 +283,7 @@ pub trait Rng {
/// let rng = rand::task_rng(); /// let rng = rand::task_rng();
/// let x: ~[uint] = rng.gen_vec(10); /// let x: ~[uint] = rng.gen_vec(10);
/// println!("{:?}", x); /// println!("{:?}", x);
/// println!("{:?}", rng.gen_vec::<(float, bool)>(5)); /// println!("{:?}", rng.gen_vec::<(f64, bool)>(5));
/// } /// }
/// ``` /// ```
fn gen_vec<T: Rand>(&mut self, len: uint) -> ~[T] { fn gen_vec<T: Rand>(&mut self, len: uint) -> ~[T] {
@ -936,10 +929,10 @@ mod test {
} }
#[test] #[test]
fn test_gen_float() { fn test_gen_f64() {
let mut r = rng(); let mut r = rng();
let a = r.gen::<float>(); let a = r.gen::<f64>();
let b = r.gen::<float>(); let b = r.gen::<f64>();
debug2!("{:?}", (a, b)); debug2!("{:?}", (a, b));
} }
@ -1049,7 +1042,7 @@ mod test {
let _many : ((), let _many : ((),
(~uint, @int, ~Option<~(@u32, ~(@bool,))>), (~uint, @int, ~Option<~(@u32, ~(@bool,))>),
(u8, i8, u16, i16, u32, i32, u64, i64), (u8, i8, u16, i16, u32, i32, u64, i64),
(f32, (f64, (float,)))) = random(); (f32, (f64, (f64,)))) = random();
} }
#[test] #[test]

View file

@ -166,6 +166,7 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
true true
} }
#[cfg(stage0)]
fn visit_float(&mut self) -> bool { fn visit_float(&mut self) -> bool {
self.align_to::<float>(); self.align_to::<float>();
if ! self.inner.visit_float() { return false; } if ! self.inner.visit_float() { return false; }

View file

@ -78,13 +78,6 @@ int_repr!(u16, "u16")
int_repr!(u32, "u32") int_repr!(u32, "u32")
int_repr!(u64, "u64") 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 { macro_rules! num_repr(($ty:ident, $suffix:expr) => (impl Repr for $ty {
fn write_repr(&self, writer: &mut io::Writer) { fn write_repr(&self, writer: &mut io::Writer) {
let s = self.to_str(); let s = self.to_str();
@ -278,7 +271,8 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
fn visit_u32(&mut self) -> bool { self.write::<u32>() } fn visit_u32(&mut self) -> bool { self.write::<u32>() }
fn visit_u64(&mut self) -> bool { self.write::<u64>() } fn visit_u64(&mut self) -> bool { self.write::<u64>() }
fn visit_float(&mut self) -> bool { self.write::<float>() } #[cfg(stage0)]
fn visit_float(&mut self) -> bool { self.write::<f64>() }
fn visit_f32(&mut self) -> bool { self.write::<f32>() } fn visit_f32(&mut self) -> bool { self.write::<f32>() }
fn visit_f64(&mut self) -> bool { self.write::<f64>() } fn visit_f64(&mut self) -> bool { self.write::<f64>() }
@ -632,7 +626,7 @@ pub fn write_repr<T>(writer: &mut io::Writer, object: &T) {
} }
#[cfg(test)] #[cfg(test)]
struct P {a: int, b: float} struct P {a: int, b: f64}
#[test] #[test]
fn test_repr() { fn test_repr() {
@ -653,7 +647,7 @@ fn test_repr() {
exact_test(&10, "10"); exact_test(&10, "10");
exact_test(&true, "true"); exact_test(&true, "true");
exact_test(&false, "false"); 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(&(@"hello"), "@\"hello\""); exact_test(&(@"hello"), "@\"hello\"");
exact_test(&(~"he\u10f3llo"), "~\"he\\u10f3llo\""); exact_test(&(~"he\u10f3llo"), "~\"he\\u10f3llo\"");
@ -682,11 +676,11 @@ fn test_repr() {
exact_test(&(&["hi", "there"]), exact_test(&(&["hi", "there"]),
"&[\"hi\", \"there\"]"); "&[\"hi\", \"there\"]");
exact_test(&(P{a:10, b:1.234}), 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}), 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}), 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"), exact_test(&(10u8, ~"hello"),
"(10u8, ~\"hello\")"); "(10u8, ~\"hello\")");
exact_test(&(10u16, ~"hello"), exact_test(&(10u16, ~"hello"),

View file

@ -109,7 +109,6 @@ pub mod prelude;
#[path = "num/u32.rs"] pub mod u32; #[path = "num/u32.rs"] pub mod u32;
#[path = "num/u64.rs"] pub mod u64; #[path = "num/u64.rs"] pub mod u64;
#[path = "num/float.rs"] pub mod float;
#[path = "num/f32.rs"] pub mod f32; #[path = "num/f32.rs"] pub mod f32;
#[path = "num/f64.rs"] pub mod f64; #[path = "num/f64.rs"] pub mod f64;

View file

@ -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 { impl IterBytes for f32 {
#[inline] #[inline]
fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {

View file

@ -480,7 +480,7 @@ pub mod ct {
#[doc(hidden)] #[doc(hidden)]
#[allow(non_uppercase_statics)] #[allow(non_uppercase_statics)]
pub mod rt { pub mod rt {
use float; use f64;
use str; use str;
use sys; use sys;
use num; use num;
@ -563,10 +563,10 @@ pub mod rt {
}; };
pad(cv, unpadded, None, PadNozero, buf); 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 { let (to_str, digits) = match cv.precision {
CountIs(c) => (float::to_str_exact, c as uint), CountIs(c) => (f64::to_str_exact, c as uint),
CountImplied => (float::to_str_digits, 6u) CountImplied => (f64::to_str_digits, 6u)
}; };
let s = to_str(f, digits); let s = to_str(f, digits);
let head = if 0.0 <= f { let head = if 0.0 <= f {

View file

@ -94,6 +94,7 @@ pub trait TyVisitor {
fn visit_u32(&mut self) -> bool; fn visit_u32(&mut self) -> bool;
fn visit_u64(&mut self) -> bool; fn visit_u64(&mut self) -> bool;
#[cfg(stage0)]
fn visit_float(&mut self) -> bool; fn visit_float(&mut self) -> bool;
fn visit_f32(&mut self) -> bool; fn visit_f32(&mut self) -> bool;
fn visit_f64(&mut self) -> bool; fn visit_f64(&mut self) -> bool;

View file

@ -765,7 +765,6 @@ impl ToStr for uint_ty {
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum float_ty { pub enum float_ty {
ty_f,
ty_f32, ty_f32,
ty_f64, ty_f64,
} }

View file

@ -190,7 +190,7 @@ pub fn uint_ty_max(t: uint_ty) -> u64 {
} }
pub fn float_ty_to_str(t: float_ty) -> ~str { 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 { pub fn is_call_expr(e: @Expr) -> bool {

View file

@ -446,7 +446,6 @@ fn mk_token(cx: @ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr {
LIT_FLOAT(fident, fty) => { LIT_FLOAT(fident, fty) => {
let s_fty = match fty { let s_fty = match fty {
ast::ty_f => ~"ty_f",
ast::ty_f32 => ~"ty_f32", ast::ty_f32 => ~"ty_f32",
ast::ty_f64 => ~"ty_f64" ast::ty_f64 => ~"ty_f64"
}; };

View file

@ -530,7 +530,6 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
None => () None => ()
} }
let mut is_machine_float = false;
if rdr.curr == 'f' { if rdr.curr == 'f' {
bump(rdr); bump(rdr);
c = rdr.curr; 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 32-bit or 64-bit float, it won't be noticed till the
back-end. */ back-end. */
} else { } else {
is_float = true; fatal_span(rdr, start_bpos, rdr.last_pos, ~"expected `f32` or `f64` suffix");
is_machine_float = true;
} }
} }
if is_float { 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)); return token::LIT_FLOAT_UNSUFFIXED(str_to_ident(num_str));
} else { } else {
if num_str.len() == 0u { if num_str.len() == 0u {

View file

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

View file

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

View file

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

View file

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

View file

@ -19,16 +19,16 @@ use std::rand;
use std::uint; use std::uint;
struct Results { struct Results {
sequential_ints: float, sequential_ints: f64,
random_ints: float, random_ints: f64,
delete_ints: float, delete_ints: f64,
sequential_strings: float, sequential_strings: f64,
random_strings: float, random_strings: f64,
delete_strings: float delete_strings: f64
} }
fn timed(result: &mut float, op: &fn()) { fn timed(result: &mut f64, op: &fn()) {
let start = extra::time::precise_time_s(); let start = extra::time::precise_time_s();
op(); op();
let end = extra::time::precise_time_s(); let end = extra::time::precise_time_s();
@ -127,7 +127,7 @@ fn write_header(header: &str) {
io::stdout().write_str("\n"); 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)); 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 { fn empty_results() -> Results {
Results { Results {
sequential_ints: 0f, sequential_ints: 0.0,
random_ints: 0f, random_ints: 0.0,
delete_ints: 0f, delete_ints: 0.0,
sequential_strings: 0f, sequential_strings: 0.0,
random_strings: 0f, random_strings: 0.0,
delete_strings: 0f, delete_strings: 0.0,
} }
} }

View file

@ -55,7 +55,7 @@ fn maybe_run_test(argv: &[~str], name: ~str, test: &fn()) {
test(); test();
let stop = precise_time_s(); 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() { fn shift_push() {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -8,15 +8,15 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
fn compute1() -> float { fn compute1() -> f64 {
let v = ~[0f, 1f, 2f, 3f]; 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 `()` //~^ ERROR mismatched types: expected `()`
} }
fn main() { fn main() {
let x = compute1(); let x = compute1();
info2!("{:?}", x); info2!("{:?}", x);
assert_eq!(x, -4f); assert_eq!(x, -4f64);
} }

View file

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

View file

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

View file

@ -12,12 +12,12 @@
use std::io; use std::io;
struct Point { struct Point {
x: float, x: f64,
y: float, y: f64,
} }
impl ToStr for Point { //~ ERROR implements a method not defined in the trait 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 } Point { x: x, y: y }
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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() { pub fn main() {
assert_approx_eq!(1.0000001f, 1.0f, 1.0e-7); assert_approx_eq!(1.0000001f64, 1.0f64, 1.0e-7);
} }

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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() { pub fn main() {
assert_approx_eq!(1.00001f, 1.0f); assert_approx_eq!(1.00001f64, 1.0);
} }

View file

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

View file

@ -9,10 +9,10 @@
// except according to those terms. // except according to those terms.
pub fn main() { 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: // Trailing expressions don't require parentheses:
let y = do v.iter().fold(0f) |x, y| { x + *y } + 10f; let y = do v.iter().fold(0.0) |x, y| { x + *y } + 10.0;
assert_eq!(y, 15f); assert_eq!(y, 15.0);
} }

View file

@ -10,7 +10,7 @@
pub fn main() { pub fn main() {
fn f(i: &fn() -> uint) -> uint { i() } 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 }; let z = do do v.iter().fold(f) |x, _y| { x } { 22u };
assert_eq!(z, 22u); assert_eq!(z, 22u);
} }

View file

@ -10,7 +10,7 @@
pub fn main() { pub fn main() {
fn f(i: uint) -> uint { i } 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); let z = do v.iter().fold(f) |x, _y| { x } (22u);
assert_eq!(z, 22u); assert_eq!(z, 22u);
} }

View file

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

View file

@ -1,18 +1,18 @@
static a: int = -4 + 3; static a: int = -4 + 3;
static a2: uint = 3 + 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 c: int = 3 - 4;
static d: uint = 3 - 3; 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 e2: int = -3 * 3;
static f: uint = 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 h: int = 3 / -1;
static i: uint = 3 / 3; static i: uint = 3 / 3;
static j: float = 3.3 / 3.3; static j: f64 = 3.3 / 3.3;
static n: bool = true && false; static n: bool = true && false;

View file

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

View file

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

View file

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

View file

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

View file

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

Some files were not shown because too many files have changed in this diff Show more