mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-06-23 12:39:42 +00:00
Merge pull request #314 from JacksonUtsch/patch-1
Update Floating-Point 7 for compiler verification
This commit is contained in:
@ -93,14 +93,19 @@ fn main() {
|
|||||||
|
|
||||||
```rust,editable
|
```rust,editable
|
||||||
|
|
||||||
// Replace ? with your answer
|
// Fill the blank to make it work
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = 1_000.000_1; // ?
|
let x = 1_000.000_1; // ?
|
||||||
let y: f32 = 0.12; // f32
|
let y: f32 = 0.12; // f32
|
||||||
let z = 0.01_f64; // f64
|
let z = 0.01_f64; // f64
|
||||||
|
|
||||||
|
assert_eq!(type_of(&x), "__".to_string());
|
||||||
println!("Success!");
|
println!("Success!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn type_of<T>(_: &T) -> String {
|
||||||
|
format!("{}", std::any::type_name::<T>())
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
8. 🌟🌟 Make it work in two distinct ways
|
8. 🌟🌟 Make it work in two distinct ways
|
||||||
|
@ -68,6 +68,13 @@ fn main() {
|
|||||||
let x = 1_000.000_1; // f64
|
let x = 1_000.000_1; // f64
|
||||||
let y: f32 = 0.12; // f32
|
let y: f32 = 0.12; // f32
|
||||||
let z = 0.01_f64; // f64
|
let z = 0.01_f64; // f64
|
||||||
|
|
||||||
|
assert_eq!(type_of(&x), "f64".to_string());
|
||||||
|
println!("Success!");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn type_of<T>(_: &T) -> String {
|
||||||
|
format!("{}", std::any::type_name::<T>())
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user