Skip to content

Commit 3797f2b

Browse files
committed
Capitalize statics in f32 and f64 mods
Fixes #10077
1 parent cd6e9f4 commit 3797f2b

File tree

8 files changed

+169
-175
lines changed

8 files changed

+169
-175
lines changed

doc/tutorial.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ types.
491491
use std::f64;
492492
use std::num::atan;
493493
fn angle(vector: (f64, f64)) -> f64 {
494-
let pi = f64::consts::pi;
494+
let pi = f64::consts::PI;
495495
match vector {
496496
(0.0, y) if y < 0.0 => 1.5 * pi,
497497
(0.0, y) => 0.5 * pi,
@@ -689,7 +689,7 @@ use std::f64;
689689
# enum Shape { Circle(Point, f64), Rectangle(Point, Point) }
690690
fn area(sh: Shape) -> f64 {
691691
match sh {
692-
Circle(_, size) => f64::consts::pi * size * size,
692+
Circle(_, size) => f64::consts::PI * size * size,
693693
Rectangle(Point { x, y }, Point { x: x2, y: y2 }) => (x2 - x) * (y2 - y)
694694
}
695695
}
@@ -725,7 +725,7 @@ enum Shape {
725725
}
726726
fn area(sh: Shape) -> f64 {
727727
match sh {
728-
Circle { radius: radius, _ } => f64::consts::pi * square(radius),
728+
Circle { radius: radius, _ } => f64::consts::PI * square(radius),
729729
Rectangle { top_left: top_left, bottom_right: bottom_right } => {
730730
(bottom_right.x - top_left.x) * (top_left.y - bottom_right.y)
731731
}
@@ -1699,10 +1699,10 @@ impl Circle {
16991699
To call such a method, just prefix it with the type name and a double colon:
17001700

17011701
~~~~
1702-
use std::f64::consts::pi;
1702+
use std::f64::consts::PI;
17031703
struct Circle { radius: f64 }
17041704
impl Circle {
1705-
fn new(area: f64) -> Circle { Circle { radius: (area / pi).sqrt() } }
1705+
fn new(area: f64) -> Circle { Circle { radius: (area / PI).sqrt() } }
17061706
}
17071707
let c = Circle::new(42.5);
17081708
~~~~
@@ -1977,13 +1977,13 @@ name and a double colon. The compiler uses type inference to decide which
19771977
implementation to use.
19781978

19791979
~~~~
1980-
use std::f64::consts::pi;
1980+
use std::f64::consts::PI;
19811981
trait Shape { fn new(area: f64) -> Self; }
19821982
struct Circle { radius: f64 }
19831983
struct Square { length: f64 }
19841984
19851985
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() } }
19871987
}
19881988
impl Shape for Square {
19891989
fn new(area: f64) -> Square { Square { length: (area).sqrt() } }
@@ -2157,17 +2157,17 @@ trait Circle : Shape { fn radius(&self) -> f64; }
21572157
Now, we can implement `Circle` on a type only if we also implement `Shape`.
21582158

21592159
~~~~
2160-
use std::f64::consts::pi;
2160+
use std::f64::consts::PI;
21612161
# trait Shape { fn area(&self) -> f64; }
21622162
# trait Circle : Shape { fn radius(&self) -> f64; }
21632163
# struct Point { x: f64, y: f64 }
21642164
# fn square(x: f64) -> f64 { x * x }
21652165
struct CircleStruct { center: Point, radius: f64 }
21662166
impl Circle for CircleStruct {
2167-
fn radius(&self) -> f64 { (self.area() / pi).sqrt() }
2167+
fn radius(&self) -> f64 { (self.area() / PI).sqrt() }
21682168
}
21692169
impl Shape for CircleStruct {
2170-
fn area(&self) -> f64 { pi * square(self.radius) }
2170+
fn area(&self) -> f64 { PI * square(self.radius) }
21712171
}
21722172
~~~~
21732173

@@ -2192,13 +2192,13 @@ fn radius_times_area<T: Circle>(c: T) -> f64 {
21922192
Likewise, supertrait methods may also be called on trait objects.
21932193

21942194
~~~ {.xfail-test}
2195-
use std::f64::consts::pi;
2195+
use std::f64::consts::PI;
21962196
# trait Shape { fn area(&self) -> f64; }
21972197
# trait Circle : Shape { fn radius(&self) -> f64; }
21982198
# struct Point { x: f64, y: f64 }
21992199
# 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) } }
22022202
22032203
let concrete = @CircleStruct{center:Point{x:3f,y:4f},radius:5f};
22042204
let mycircle: @Circle = concrete as @Circle;

0 commit comments

Comments
 (0)