@@ -503,12 +503,13 @@ types.
503
503
504
504
~~~~
505
505
# use std::float;
506
+ # use std::num::atan;
506
507
fn angle(vector: (float, float)) -> float {
507
508
let pi = float::consts::pi;
508
509
match vector {
509
510
(0f, y) if y < 0f => 1.5 * pi,
510
511
(0f, y) => 0.5 * pi,
511
- (x, y) => float:: atan(y / x)
512
+ (x, y) => atan(y / x)
512
513
}
513
514
}
514
515
~~~~
@@ -1728,10 +1729,9 @@ To call such a method, just prefix it with the type name and a double colon:
1728
1729
1729
1730
~~~~
1730
1731
# use std::float::consts::pi;
1731
- # use std::float::sqrt;
1732
1732
struct Circle { radius: float }
1733
1733
impl Circle {
1734
- fn new(area: float) -> Circle { Circle { radius: sqrt (area / pi) } }
1734
+ fn new(area: float) -> Circle { Circle { radius: (area / pi).sqrt( ) } }
1735
1735
}
1736
1736
let c = Circle::new(42.5);
1737
1737
~~~~
@@ -1997,16 +1997,15 @@ implementation to use.
1997
1997
1998
1998
~~~~
1999
1999
# use std::float::consts::pi;
2000
- # use std::float::sqrt;
2001
2000
trait Shape { fn new(area: float) -> Self; }
2002
2001
struct Circle { radius: float }
2003
2002
struct Square { length: float }
2004
2003
2005
2004
impl Shape for Circle {
2006
- fn new(area: float) -> Circle { Circle { radius: sqrt (area / pi) } }
2005
+ fn new(area: float) -> Circle { Circle { radius: (area / pi).sqrt( ) } }
2007
2006
}
2008
2007
impl Shape for Square {
2009
- fn new(area: float) -> Square { Square { length: sqrt (area) } }
2008
+ fn new(area: float) -> Square { Square { length: (area).sqrt( ) } }
2010
2009
}
2011
2010
2012
2011
let area = 42.5;
@@ -2154,14 +2153,13 @@ Now, we can implement `Circle` on a type only if we also implement `Shape`.
2154
2153
2155
2154
~~~~
2156
2155
# use std::float::consts::pi;
2157
- # use std::float::sqrt;
2158
2156
# trait Shape { fn area(&self) -> float; }
2159
2157
# trait Circle : Shape { fn radius(&self) -> float; }
2160
2158
# struct Point { x: float, y: float }
2161
2159
# fn square(x: float) -> float { x * x }
2162
2160
struct CircleStruct { center: Point, radius: float }
2163
2161
impl Circle for CircleStruct {
2164
- fn radius(&self) -> float { sqrt (self.area() / pi) }
2162
+ fn radius(&self) -> float { (self.area() / pi).sqrt( ) }
2165
2163
}
2166
2164
impl Shape for CircleStruct {
2167
2165
fn area(&self) -> float { pi * square(self.radius) }
@@ -2190,12 +2188,11 @@ Likewise, supertrait methods may also be called on trait objects.
2190
2188
2191
2189
~~~ {.xfail-test}
2192
2190
# use std::float::consts::pi;
2193
- # use std::float::sqrt;
2194
2191
# trait Shape { fn area(&self) -> float; }
2195
2192
# trait Circle : Shape { fn radius(&self) -> float; }
2196
2193
# struct Point { x: float, y: float }
2197
2194
# struct CircleStruct { center: Point, radius: float }
2198
- # impl Circle for CircleStruct { fn radius(&self) -> float { sqrt (self.area() / pi) } }
2195
+ # impl Circle for CircleStruct { fn radius(&self) -> float { (self.area() / pi).sqrt( ) } }
2199
2196
# impl Shape for CircleStruct { fn area(&self) -> float { pi * square(self.radius) } }
2200
2197
2201
2198
let concrete = @CircleStruct{center:Point{x:3f,y:4f},radius:5f};
0 commit comments