about summary refs log tree commit diff
path: root/doc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-07-09 13:34:50 -0700
committerbors <bors@rust-lang.org>2013-07-09 13:34:50 -0700
commite388a80c234d628c4d1fab77dc3e3f2c04cbefc5 (patch)
tree694f659ded49c002e1aee01146eed625ab50c1bc /doc
parent5aa0ca9b2eb28166d9ab2e86557a5b1f84230b46 (diff)
parent20a2fbd05557b21b7e3f38d17250388a350d3484 (diff)
downloadrust-e388a80c234d628c4d1fab77dc3e3f2c04cbefc5.tar.gz
rust-e388a80c234d628c4d1fab77dc3e3f2c04cbefc5.zip
auto merge of #7117 : jensnockert/rust/freestanding, r=cmr
The free-standing functions in f32, f64, i8, i16, i32, i64, u8, u16,
u32, u64, float, int, and uint are replaced with generic functions in
num instead.

This means that instead of having to know everywhere what the type is, like

~~~
f64::sin(x)
~~~

You can simply write code that uses the type-generic versions in num instead, this works for all types that implement the corresponding trait in num.

~~~
num::sin(x)
~~~

Note 1: If you were previously using any of those functions, just replace them
with the corresponding function with the same name in num.

Note 2: If you were using a function that corresponds to an operator, use the
operator instead.

Note 3: This is just https://github.com/mozilla/rust/pull/7090 reopened against master.
Diffstat (limited to 'doc')
-rw-r--r--doc/rust.md4
-rw-r--r--doc/tutorial.md17
2 files changed, 9 insertions, 12 deletions
diff --git a/doc/rust.md b/doc/rust.md
index 42a010b114a..0a640648222 100644
--- a/doc/rust.md
+++ b/doc/rust.md
@@ -802,11 +802,11 @@ Use declarations support a number of convenient shortcuts:
 An example of `use` declarations:
 
 ~~~~
-use std::float::sin;
+use std::num::sin;
 use std::option::{Some, None};
 
 fn main() {
-    // Equivalent to 'info!(std::float::sin(1.0));'
+    // Equivalent to 'info!(std::num::sin(1.0));'
     info!(sin(1.0));
 
     // Equivalent to 'info!(~[std::option::Some(1.0), std::option::None]);'
diff --git a/doc/tutorial.md b/doc/tutorial.md
index c8280a99182..b282679b1a1 100644
--- a/doc/tutorial.md
+++ b/doc/tutorial.md
@@ -503,12 +503,13 @@ types.
 
 ~~~~
 # use std::float;
+# use std::num::atan;
 fn angle(vector: (float, float)) -> float {
     let pi = float::consts::pi;
     match vector {
       (0f, y) if y < 0f => 1.5 * pi,
       (0f, y) => 0.5 * pi,
-      (x, y) => float::atan(y / x)
+      (x, y) => atan(y / x)
     }
 }
 ~~~~
@@ -1728,10 +1729,9 @@ To call such a method, just prefix it with the type name and a double colon:
 
 ~~~~
 # use std::float::consts::pi;
-# use std::float::sqrt;
 struct Circle { radius: float }
 impl Circle {
-    fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
+    fn new(area: float) -> Circle { Circle { radius: (area / pi).sqrt() } }
 }
 let c = Circle::new(42.5);
 ~~~~
@@ -1997,16 +1997,15 @@ implementation to use.
 
 ~~~~
 # use std::float::consts::pi;
-# use std::float::sqrt;
 trait Shape { fn new(area: float) -> Self; }
 struct Circle { radius: float }
 struct Square { length: float }
 
 impl Shape for Circle {
-    fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
+    fn new(area: float) -> Circle { Circle { radius: (area / pi).sqrt() } }
 }
 impl Shape for Square {
-    fn new(area: float) -> Square { Square { length: sqrt(area) } }
+    fn new(area: float) -> Square { Square { length: (area).sqrt() } }
 }
 
 let area = 42.5;
@@ -2154,14 +2153,13 @@ Now, we can implement `Circle` on a type only if we also implement `Shape`.
 
 ~~~~
 # use std::float::consts::pi;
-# use std::float::sqrt;
 # trait Shape { fn area(&self) -> float; }
 # trait Circle : Shape { fn radius(&self) -> float; }
 # struct Point { x: float, y: float }
 # fn square(x: float) -> float { x * x }
 struct CircleStruct { center: Point, radius: float }
 impl Circle for CircleStruct {
-    fn radius(&self) -> float { sqrt(self.area() / pi) }
+    fn radius(&self) -> float { (self.area() / pi).sqrt() }
 }
 impl Shape for CircleStruct {
     fn area(&self) -> float { pi * square(self.radius) }
@@ -2190,12 +2188,11 @@ Likewise, supertrait methods may also be called on trait objects.
 
 ~~~ {.xfail-test}
 # use std::float::consts::pi;
-# use std::float::sqrt;
 # trait Shape { fn area(&self) -> float; }
 # trait Circle : Shape { fn radius(&self) -> float; }
 # struct Point { x: float, y: float }
 # struct CircleStruct { center: Point, radius: float }
-# impl Circle for CircleStruct { fn radius(&self) -> float { sqrt(self.area() / pi) } }
+# impl Circle for CircleStruct { fn radius(&self) -> float { (self.area() / pi).sqrt() } }
 # impl Shape for CircleStruct { fn area(&self) -> float { pi * square(self.radius) } }
 
 let concrete = @CircleStruct{center:Point{x:3f,y:4f},radius:5f};