diff options
| author | bors <bors@rust-lang.org> | 2014-04-01 13:26:49 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-04-01 13:26:49 -0700 |
| commit | 1217cfb9e7e449c9ef5ee0844e7d3be324648f02 (patch) | |
| tree | ce831ee4530348b32b5ccbb6c0dfa1d15df3279e /src/doc/tutorial.md | |
| parent | b71c02e512fcfe18ea7a5a8a99ac758b4fa564a6 (diff) | |
| parent | 5e12e1b1a49134f578e1778f4a1216221417bc5e (diff) | |
| download | rust-1217cfb9e7e449c9ef5ee0844e7d3be324648f02.tar.gz rust-1217cfb9e7e449c9ef5ee0844e7d3be324648f02.zip | |
auto merge of #13225 : thestinger/rust/num, r=cmr
The `Float` trait methods will be usable as functions via UFCS, and we came to a consensus to remove duplicate functions like this a long time ago. It does still make sense to keep the duplicate functions when the trait methods are static, unless the decision to leave out the in-scope trait name resolution for static methods changes.
Diffstat (limited to 'src/doc/tutorial.md')
| -rw-r--r-- | src/doc/tutorial.md | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/doc/tutorial.md b/src/doc/tutorial.md index 3423a5e090e..62e0fabdc05 100644 --- a/src/doc/tutorial.md +++ b/src/doc/tutorial.md @@ -504,13 +504,12 @@ matching in order to bind names to the contents of data types. ~~~~ use std::f64; -use std::num::atan; fn angle(vector: (f64, f64)) -> f64 { let pi = f64::consts::PI; match vector { (0.0, y) if y < 0.0 => 1.5 * pi, (0.0, _) => 0.5 * pi, - (x, y) => atan(y / x) + (x, y) => (y / x).atan() } } ~~~~ @@ -1430,12 +1429,11 @@ bad, but often copies are expensive. So we’d like to define a function that takes the points by pointer. We can use references to do this: ~~~ -use std::num::sqrt; # struct Point { x: f64, y: f64 } fn compute_distance(p1: &Point, p2: &Point) -> f64 { let x_d = p1.x - p2.x; let y_d = p1.y - p2.y; - sqrt(x_d * x_d + y_d * y_d) + (x_d * x_d + y_d * y_d).sqrt() } ~~~ @@ -2303,7 +2301,7 @@ impl Shape for Circle { fn new(area: f64) -> Circle { Circle { radius: (area / PI).sqrt() } } } impl Shape for Square { - fn new(area: f64) -> Square { Square { length: (area).sqrt() } } + fn new(area: f64) -> Square { Square { length: area.sqrt() } } } let area = 42.5; |
