From fc3bbc481c567d737f1e46341e5a7f2db659dd33 Mon Sep 17 00:00:00 2001 From: sunface Date: Thu, 24 Feb 2022 20:31:19 +0800 Subject: [PATCH] update numbers --- en/src/SUMMARY.md | 2 +- en/src/basic-types/intro.md | 4 ++ en/src/basic-types/numbers.md | 85 ++++++++++++++++++++++++++++++++++ en/src/variables.md | 8 ++-- zh-CN/src/SUMMARY.md | 2 +- zh-CN/src/basic-types/intro.md | 6 ++- zh-CN/src/circle-refer | 1 - zh-CN/src/crate | 1 - zh-CN/src/resu | 1 - 9 files changed, 100 insertions(+), 10 deletions(-) delete mode 100644 zh-CN/src/circle-refer delete mode 100644 zh-CN/src/crate delete mode 100644 zh-CN/src/resu diff --git a/en/src/SUMMARY.md b/en/src/SUMMARY.md index f0330e9..fc832f9 100644 --- a/en/src/SUMMARY.md +++ b/en/src/SUMMARY.md @@ -2,7 +2,7 @@ - [About Exercise.rs](why-exercise.md) - [Variables](variables.md) -- [Basic Types todo](basic-types/intro.md) +- [Basic Types](basic-types/intro.md) - [Numbers](basic-types/numbers.md) - [Char, Bool and Unit](basic-types/char-bool-unit.md) - [Statements and Expressions](basic-types/statements-expressions.md) diff --git a/en/src/basic-types/intro.md b/en/src/basic-types/intro.md index 2d47759..a2937e8 100644 --- a/en/src/basic-types/intro.md +++ b/en/src/basic-types/intro.md @@ -1 +1,5 @@ # Basic Types +Learning resources: +- English: [Rust Book 3.2 and 3.3](https://doc.rust-lang.org/book/ch03-02-data-types.html) +- 简体中文: [Rust语言圣经 - 基本类型](https://course.rs/basic/base-type/index.html) + diff --git a/en/src/basic-types/numbers.md b/en/src/basic-types/numbers.md index bbdcf5e..9201c67 100644 --- a/en/src/basic-types/numbers.md +++ b/en/src/basic-types/numbers.md @@ -1 +1,86 @@ # Numbers + +### Integer + +🌟 remove something to make it work + +> Tips: If we don't explicitly give one type to a varible, then the compiler will infer one for us +```rust,editable + +fn main() { + let x: i32 = 5; + let mut y: u32 = 5; + + y = x; + + let z = 10; // type of z ? +} +``` + + +🌟🌟🌟 modify `assert_eq!` to make it work + +> Tips: If we don't explicitly give one type to a varible, then the compiler will infer one for us + +```rust,editable + +fn main() { + let x = 5; + assert_eq!("u32".to_string(), type_of(&x)); +} + +// get the type of given variable, return a string representation of the type , e.g "i8", "u8", "i32", "u32" +fn type_of(_: &T) -> String { + format!("{}", std::any::type_name::()) +} +``` + +🌟🌟 fill the blanks to make it work +```rust,editable + +fn main() { + assert_eq!(i8::MAX, __); + assert_eq!(u8::MAX, __); +} +``` + +🌟🌟 fix errors and panics to make it work +```rust,editable + +fn main() { + let v1 = 251_u8 + 8; + let v2 = i8::checked_add(251, 8).unwrap(); + println!("{},{}",v1,v2); +} +``` + +🌟🌟🌟 modify `assert!` to make it work +```rust,editable + +fn main() { + let v = 1_024 + 0xff + 0o77 + 0b1111_1111; + assert!(v == 1579); +} +``` + +### Floating-Point +🌟 replace ? with your answer + +```rust,editable + +fn main() { + let x = 1_000.000_1; // ? + let y: f32 = 0.12; // f32 + let z = 0.01_f64; // f64 +} +``` +🌟🌟🌟 use two ways to make it work + +> Tips: 1. abs 2. f32 + +```rust,editable + +fn main() { + assert!(0.1+0.2==0.3); +} +``` \ No newline at end of file diff --git a/en/src/variables.md b/en/src/variables.md index 7d9482a..99fb0ef 100644 --- a/en/src/variables.md +++ b/en/src/variables.md @@ -1,7 +1,7 @@ # Variables ### Binding and mutablity -🌟 fix the error below with least change +🌟 fix the error below with least modifying ```rust,editable fn main() { @@ -24,7 +24,7 @@ fn main() { ``` ### Scope -🌟 fix the error below with least change +🌟 fix the error below with least modifying ```rust,editable fn main() { @@ -50,7 +50,7 @@ fn define_x() { ``` ### Shadowing -🌟🌟 only change `assert_eq!` to make the `println!` work(print `42` in terminal) +🌟🌟 only modify `assert_eq!` to make the `println!` work(print `42` in terminal) ```rust,editable @@ -103,7 +103,7 @@ fn main() { ``` ### Destructing -🌟🌟 fix the error below with least change +🌟🌟 fix the error below with least modifying > Tips: you can use Shadowing or Mutability diff --git a/zh-CN/src/SUMMARY.md b/zh-CN/src/SUMMARY.md index 6c71278..305b422 100644 --- a/zh-CN/src/SUMMARY.md +++ b/zh-CN/src/SUMMARY.md @@ -2,7 +2,7 @@ - [关于 exercise.rs](why-exercise.md) - [变量绑定与解构](variables.md) -- [基本类型 todo](basic-types/intro.md) +- [基本类型](basic-types/intro.md) - [数值类型](basic-types/numbers.md) - [字符、布尔、单元类型](basic-types/char-bool-unit.md) - [语句与表达式](basic-types/statements-expressions.md) diff --git a/zh-CN/src/basic-types/intro.md b/zh-CN/src/basic-types/intro.md index 2d47759..245efe7 100644 --- a/zh-CN/src/basic-types/intro.md +++ b/zh-CN/src/basic-types/intro.md @@ -1 +1,5 @@ -# Basic Types +# 基本类型 +学习资料: +- English: [Rust Book 3.2 and 3.3](https://doc.rust-lang.org/book/ch03-02-data-types.html) +- 简体中文: [Rust语言圣经 - 基本类型](https://course.rs/basic/base-type/index.html) + diff --git a/zh-CN/src/circle-refer b/zh-CN/src/circle-refer deleted file mode 100644 index 04b7a8f..0000000 --- a/zh-CN/src/circle-refer +++ /dev/null @@ -1 +0,0 @@ -# Weak and Circle reference diff --git a/zh-CN/src/crate b/zh-CN/src/crate deleted file mode 100644 index e66fb06..0000000 --- a/zh-CN/src/crate +++ /dev/null @@ -1 +0,0 @@ -# Crate diff --git a/zh-CN/src/resu b/zh-CN/src/resu deleted file mode 100644 index b82dd9a..0000000 --- a/zh-CN/src/resu +++ /dev/null @@ -1 +0,0 @@ -# panic!