@@ -491,7 +491,7 @@ types.
491
491
use std::f64;
492
492
use std::num::atan;
493
493
fn angle(vector: (f64, f64)) -> f64 {
494
- let pi = f64::consts::pi ;
494
+ let pi = f64::consts::PI ;
495
495
match vector {
496
496
(0.0, y) if y < 0.0 => 1.5 * pi,
497
497
(0.0, y) => 0.5 * pi,
@@ -689,7 +689,7 @@ use std::f64;
689
689
# enum Shape { Circle(Point, f64), Rectangle(Point, Point) }
690
690
fn area(sh: Shape) -> f64 {
691
691
match sh {
692
- Circle(_, size) => f64::consts::pi * size * size,
692
+ Circle(_, size) => f64::consts::PI * size * size,
693
693
Rectangle(Point { x, y }, Point { x: x2, y: y2 }) => (x2 - x) * (y2 - y)
694
694
}
695
695
}
@@ -725,7 +725,7 @@ enum Shape {
725
725
}
726
726
fn area(sh: Shape) -> f64 {
727
727
match sh {
728
- Circle { radius: radius, _ } => f64::consts::pi * square(radius),
728
+ Circle { radius: radius, _ } => f64::consts::PI * square(radius),
729
729
Rectangle { top_left: top_left, bottom_right: bottom_right } => {
730
730
(bottom_right.x - top_left.x) * (top_left.y - bottom_right.y)
731
731
}
@@ -1699,10 +1699,10 @@ impl Circle {
1699
1699
To call such a method, just prefix it with the type name and a double colon:
1700
1700
1701
1701
~~~~
1702
- use std::f64::consts::pi ;
1702
+ use std::f64::consts::PI ;
1703
1703
struct Circle { radius: f64 }
1704
1704
impl Circle {
1705
- fn new(area: f64) -> Circle { Circle { radius: (area / pi ).sqrt() } }
1705
+ fn new(area: f64) -> Circle { Circle { radius: (area / PI ).sqrt() } }
1706
1706
}
1707
1707
let c = Circle::new(42.5);
1708
1708
~~~~
@@ -1977,13 +1977,13 @@ name and a double colon. The compiler uses type inference to decide which
1977
1977
implementation to use.
1978
1978
1979
1979
~~~~
1980
- use std::f64::consts::pi ;
1980
+ use std::f64::consts::PI ;
1981
1981
trait Shape { fn new(area: f64) -> Self; }
1982
1982
struct Circle { radius: f64 }
1983
1983
struct Square { length: f64 }
1984
1984
1985
1985
impl Shape for Circle {
1986
- fn new(area: f64) -> Circle { Circle { radius: (area / pi ).sqrt() } }
1986
+ fn new(area: f64) -> Circle { Circle { radius: (area / PI ).sqrt() } }
1987
1987
}
1988
1988
impl Shape for Square {
1989
1989
fn new(area: f64) -> Square { Square { length: (area).sqrt() } }
@@ -2157,17 +2157,17 @@ trait Circle : Shape { fn radius(&self) -> f64; }
2157
2157
Now, we can implement ` Circle ` on a type only if we also implement ` Shape ` .
2158
2158
2159
2159
~~~~
2160
- use std::f64::consts::pi ;
2160
+ use std::f64::consts::PI ;
2161
2161
# trait Shape { fn area(&self) -> f64; }
2162
2162
# trait Circle : Shape { fn radius(&self) -> f64; }
2163
2163
# struct Point { x: f64, y: f64 }
2164
2164
# fn square(x: f64) -> f64 { x * x }
2165
2165
struct CircleStruct { center: Point, radius: f64 }
2166
2166
impl Circle for CircleStruct {
2167
- fn radius(&self) -> f64 { (self.area() / pi ).sqrt() }
2167
+ fn radius(&self) -> f64 { (self.area() / PI ).sqrt() }
2168
2168
}
2169
2169
impl Shape for CircleStruct {
2170
- fn area(&self) -> f64 { pi * square(self.radius) }
2170
+ fn area(&self) -> f64 { PI * square(self.radius) }
2171
2171
}
2172
2172
~~~~
2173
2173
@@ -2192,13 +2192,13 @@ fn radius_times_area<T: Circle>(c: T) -> f64 {
2192
2192
Likewise, supertrait methods may also be called on trait objects.
2193
2193
2194
2194
~~~ {.xfail-test}
2195
- use std::f64::consts::pi ;
2195
+ use std::f64::consts::PI ;
2196
2196
# trait Shape { fn area(&self) -> f64; }
2197
2197
# trait Circle : Shape { fn radius(&self) -> f64; }
2198
2198
# struct Point { x: f64, y: f64 }
2199
2199
# struct CircleStruct { center: Point, radius: f64 }
2200
- # impl Circle for CircleStruct { fn radius(&self) -> f64 { (self.area() / pi ).sqrt() } }
2201
- # impl Shape for CircleStruct { fn area(&self) -> f64 { pi * square(self.radius) } }
2200
+ # impl Circle for CircleStruct { fn radius(&self) -> f64 { (self.area() / PI ).sqrt() } }
2201
+ # impl Shape for CircleStruct { fn area(&self) -> f64 { PI * square(self.radius) } }
2202
2202
2203
2203
let concrete = @CircleStruct{center:Point{x:3f,y:4f},radius:5f};
2204
2204
let mycircle: @Circle = concrete as @Circle;
0 commit comments