@@ -363,19 +363,17 @@ A _floating-point literal_ has one of two forms:
363
363
second decimal literal.
364
364
* A single _ decimal literal_ followed by an _ exponent_ .
365
365
366
- By default, a floating-point literal is of type ` float ` . A
367
- floating-point literal may be followed (immediately, without any
368
- spaces) by a _ floating-point suffix_ , which changes the type of the
369
- literal. There are three floating-point suffixes: ` f ` (for the base
370
- ` float ` type), ` f32 ` , and ` f64 ` (the 32-bit and 64-bit floating point
371
- types).
366
+ By default, a floating-point literal has a generic type, but will fall back to
367
+ ` f64 ` . A floating-point literal may be followed (immediately, without any
368
+ spaces) by a _ floating-point suffix_ , which changes the type of the literal.
369
+ There are two floating-point suffixes: ` f32 ` , and ` f64 ` (the 32-bit and 64-bit
370
+ floating point types).
372
371
373
372
Examples of floating-point literals of various forms:
374
373
375
374
~~~~
376
- 123.0; // type float
377
- 0.1; // type float
378
- 3f; // type float
375
+ 123.0; // type f64
376
+ 0.1; // type f64
379
377
0.1f32; // type f32
380
378
12E+99_f64; // type f64
381
379
~~~~
@@ -683,15 +681,15 @@ mod math {
683
681
type complex = (f64, f64);
684
682
fn sin(f: f64) -> f64 {
685
683
...
686
- # fail !();
684
+ # fail2 !();
687
685
}
688
686
fn cos(f: f64) -> f64 {
689
687
...
690
- # fail !();
688
+ # fail2 !();
691
689
}
692
690
fn tan(f: f64) -> f64 {
693
691
...
694
- # fail !();
692
+ # fail2 !();
695
693
}
696
694
}
697
695
~~~~~~~~
@@ -817,12 +815,14 @@ An example of `use` declarations:
817
815
use std::num::sin;
818
816
use std::option::{Some, None};
819
817
818
+ # fn foo<T>(_: T){}
819
+
820
820
fn main() {
821
- // Equivalent to 'info!( std::num::sin(1.0) );'
822
- info!( sin(1.0) );
821
+ // Equivalent to 'std::num::sin(1.0);'
822
+ sin(1.0);
823
823
824
- // Equivalent to 'info! (~[std::option::Some(1.0), std::option::None]);'
825
- info! (~[Some(1.0), None]);
824
+ // Equivalent to 'foo (~[std::option::Some(1.0), std::option::None]);'
825
+ foo (~[Some(1.0), None]);
826
826
}
827
827
~~~~
828
828
@@ -1040,8 +1040,8 @@ output slot type would normally be. For example:
1040
1040
1041
1041
~~~~
1042
1042
fn my_err(s: &str) -> ! {
1043
- info!( s);
1044
- fail !();
1043
+ info2!("{}", s);
1044
+ fail2 !();
1045
1045
}
1046
1046
~~~~
1047
1047
@@ -1059,7 +1059,7 @@ were declared without the `!` annotation, the following code would not
1059
1059
typecheck:
1060
1060
1061
1061
~~~~
1062
- # fn my_err(s: &str) -> ! { fail !() }
1062
+ # fn my_err(s: &str) -> ! { fail2 !() }
1063
1063
1064
1064
fn f(i: int) -> int {
1065
1065
if i == 42 {
@@ -1177,8 +1177,8 @@ a = Cat;
1177
1177
Enumeration constructors can have either named or unnamed fields:
1178
1178
~~~~
1179
1179
enum Animal {
1180
- Dog (~str, float ),
1181
- Cat { name: ~str, weight: float }
1180
+ Dog (~str, f64 ),
1181
+ Cat { name: ~str, weight: f64 }
1182
1182
}
1183
1183
1184
1184
let mut a: Animal = Dog(~"Cocoa", 37.2);
@@ -1342,17 +1342,17 @@ For example:
1342
1342
trait Num {
1343
1343
fn from_int(n: int) -> Self;
1344
1344
}
1345
- impl Num for float {
1346
- fn from_int(n: int) -> float { n as float }
1345
+ impl Num for f64 {
1346
+ fn from_int(n: int) -> f64 { n as f64 }
1347
1347
}
1348
- let x: float = Num::from_int(42);
1348
+ let x: f64 = Num::from_int(42);
1349
1349
~~~~
1350
1350
1351
1351
Traits may inherit from other traits. For example, in
1352
1352
1353
1353
~~~~
1354
- trait Shape { fn area() -> float ; }
1355
- trait Circle : Shape { fn radius() -> float ; }
1354
+ trait Shape { fn area() -> f64 ; }
1355
+ trait Circle : Shape { fn radius() -> f64 ; }
1356
1356
~~~~
1357
1357
1358
1358
the syntax ` Circle : Shape ` means that types that implement ` Circle ` must also have an implementation for ` Shape ` .
@@ -1365,9 +1365,9 @@ methods of the supertrait may be called on values of subtrait-bound type paramet
1365
1365
Referring to the previous example of ` trait Circle : Shape ` :
1366
1366
1367
1367
~~~
1368
- # trait Shape { fn area(&self) -> float ; }
1369
- # trait Circle : Shape { fn radius(&self) -> float ; }
1370
- fn radius_times_area<T: Circle>(c: T) -> float {
1368
+ # trait Shape { fn area(&self) -> f64 ; }
1369
+ # trait Circle : Shape { fn radius(&self) -> f64 ; }
1370
+ fn radius_times_area<T: Circle>(c: T) -> f64 {
1371
1371
// `c` is both a Circle and a Shape
1372
1372
c.radius() * c.area()
1373
1373
}
@@ -1376,10 +1376,10 @@ fn radius_times_area<T: Circle>(c: T) -> float {
1376
1376
Likewise, supertrait methods may also be called on trait objects.
1377
1377
1378
1378
~~~ {.xfail-test}
1379
- # trait Shape { fn area(&self) -> float ; }
1380
- # trait Circle : Shape { fn radius(&self) -> float ; }
1381
- # impl Shape for int { fn area(&self) -> float { 0.0 } }
1382
- # impl Circle for int { fn radius(&self) -> float { 0.0 } }
1379
+ # trait Shape { fn area(&self) -> f64 ; }
1380
+ # trait Circle : Shape { fn radius(&self) -> f64 ; }
1381
+ # impl Shape for int { fn area(&self) -> f64 { 0.0 } }
1382
+ # impl Circle for int { fn radius(&self) -> f64 { 0.0 } }
1383
1383
# let mycircle = 0;
1384
1384
1385
1385
let mycircle: Circle = @mycircle as @Circle;
@@ -1393,14 +1393,14 @@ An _implementation_ is an item that implements a [trait](#traits) for a specific
1393
1393
Implementations are defined with the keyword ` impl ` .
1394
1394
1395
1395
~~~~
1396
- # struct Point {x: float , y: float };
1396
+ # struct Point {x: f64 , y: f64 };
1397
1397
# type Surface = int;
1398
- # struct BoundingBox {x: float , y: float , width: float , height: float };
1398
+ # struct BoundingBox {x: f64 , y: f64 , width: f64 , height: f64 };
1399
1399
# trait Shape { fn draw(&self, Surface); fn bounding_box(&self) -> BoundingBox; }
1400
1400
# fn do_draw_circle(s: Surface, c: Circle) { }
1401
1401
1402
1402
struct Circle {
1403
- radius: float ,
1403
+ radius: f64 ,
1404
1404
center: Point,
1405
1405
}
1406
1406
@@ -1968,7 +1968,7 @@ values.
1968
1968
1969
1969
~~~~~~~~ {.tuple}
1970
1970
(0,);
1971
- (0f , 4.5f );
1971
+ (0.0 , 4.5 );
1972
1972
("a", 4u, true);
1973
1973
~~~~~~~~
1974
1974
@@ -2000,12 +2000,12 @@ A _unit-like structure expression_ consists only of the [path](#paths) of a [str
2000
2000
The following are examples of structure expressions:
2001
2001
2002
2002
~~~~
2003
- # struct Point { x: float , y: float }
2004
- # struct TuplePoint(float, float );
2003
+ # struct Point { x: f64 , y: f64 }
2004
+ # struct TuplePoint(f64, f64 );
2005
2005
# mod game { pub struct User<'self> { name: &'self str, age: uint, score: uint } }
2006
2006
# struct Cookie; fn some_fn<T>(t: T) {}
2007
- Point {x: 10f , y: 20f };
2008
- TuplePoint(10f, 20f );
2007
+ Point {x: 10.0 , y: 20.0 };
2008
+ TuplePoint(10.0, 20.0 );
2009
2009
let u = game::User {name: "Joe", age: 35, score: 100_000};
2010
2010
some_fn::<Cookie>(Cookie);
2011
2011
~~~~
@@ -2246,12 +2246,12 @@ Any other cast is unsupported and will fail to compile.
2246
2246
An example of an ` as ` expression:
2247
2247
2248
2248
~~~~
2249
- # fn sum(v: &[float ]) -> float { 0.0 }
2250
- # fn len(v: &[float ]) -> int { 0 }
2249
+ # fn sum(v: &[f64 ]) -> f64 { 0.0 }
2250
+ # fn len(v: &[f64 ]) -> int { 0 }
2251
2251
2252
- fn avg(v: &[float ]) -> float {
2253
- let sum: float = sum(v);
2254
- let sz: float = len(v) as float ;
2252
+ fn avg(v: &[f64 ]) -> f64 {
2253
+ let sum: f64 = sum(v);
2254
+ let sz: f64 = len(v) as f64 ;
2255
2255
return sum / sz;
2256
2256
}
2257
2257
~~~~
@@ -2382,7 +2382,7 @@ fn ten_times(f: &fn(int)) {
2382
2382
}
2383
2383
}
2384
2384
2385
- ten_times(|j| println(fmt !("hello, %d ", j) ));
2385
+ ten_times(|j| println!("hello, {} ", j));
2386
2386
2387
2387
~~~~
2388
2388
@@ -2594,9 +2594,9 @@ enum List<X> { Nil, Cons(X, @List<X>) }
2594
2594
let x: List<int> = Cons(10, @Cons(11, @Nil));
2595
2595
2596
2596
match x {
2597
- Cons(_, @Nil) => fail !("singleton list"),
2597
+ Cons(_, @Nil) => fail2 !("singleton list"),
2598
2598
Cons(*) => return,
2599
- Nil => fail !("empty list")
2599
+ Nil => fail2 !("empty list")
2600
2600
}
2601
2601
~~~~
2602
2602
@@ -2633,7 +2633,7 @@ match x {
2633
2633
return;
2634
2634
}
2635
2635
_ => {
2636
- fail !();
2636
+ fail2 !();
2637
2637
}
2638
2638
}
2639
2639
~~~~
@@ -2687,7 +2687,7 @@ guard may refer to the variables bound within the pattern they follow.
2687
2687
let message = match maybe_digit {
2688
2688
Some(x) if x < 10 => process_digit(x),
2689
2689
Some(x) => process_other(x),
2690
- None => fail !()
2690
+ None => fail2 !()
2691
2691
};
2692
2692
~~~~
2693
2693
@@ -2765,19 +2765,6 @@ size, in bits, is equal to the size of the rust type `uint` on the same target
2765
2765
machine.
2766
2766
2767
2767
2768
- #### Machine-dependent floating point type
2769
-
2770
- The Rust type ` float ` is a machine-specific type equal to one of the supported
2771
- Rust floating-point machine types (` f32 ` or ` f64 ` ). It is the largest
2772
- floating-point type that is directly supported by hardware on the target
2773
- machine, or if the target machine has no floating-point hardware support, the
2774
- largest floating-point type supported by the software floating-point library
2775
- used to support the other floating-point machine types.
2776
-
2777
- Note that due to the preference for hardware-supported floating-point, the
2778
- type ` float ` may not be equal to the largest * supported* floating-point type.
2779
-
2780
-
2781
2768
### Textual types
2782
2769
2783
2770
The types ` char ` and ` str ` hold textual data.
@@ -3472,20 +3459,20 @@ that demonstrates all four of them:
3472
3459
3473
3460
``` rust
3474
3461
fn main () {
3475
- error ! (" This is an error log" )
3476
- warn ! (" This is a warn log" )
3477
- info ! (" this is an info log" )
3478
- debug ! (" This is a debug log" )
3462
+ error2 ! (" This is an error log" )
3463
+ warn2 ! (" This is a warn log" )
3464
+ info2 ! (" this is an info log" )
3465
+ debug2 ! (" This is a debug log" )
3479
3466
}
3480
3467
```
3481
3468
3482
3469
These four log levels correspond to levels 1-4, as controlled by ` RUST_LOG ` :
3483
3470
3484
3471
``` bash
3485
3472
$ RUST_LOG=rust=3 ./rust
3486
- rust: ~ " \" This is an error log\" "
3487
- rust: ~ " \" This is a warn log\" "
3488
- rust: ~ " \" this is an info log\" "
3473
+ This is an error log
3474
+ This is a warn log
3475
+ this is an info log
3489
3476
```
3490
3477
3491
3478
# Appendix: Rationales and design tradeoffs
0 commit comments