Skip to content

Commit

Permalink
add 复数
Browse files Browse the repository at this point in the history
  • Loading branch information
sunface committed Apr 6, 2022
1 parent 4281a7f commit 0880faa
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ src = "src"

[output.html]
no-section-label = true
additional-css = ["theme/style.css"]
additional-css = ["theme/style1.css"]
additional-js = ["assets/custom.js", "assets/bigPicture.js"]
git-repository-url = "https://github.com/studyrs/rusty-book"
edit-url-template = "https://github.com/studyrs/rusty-book/edit/main/{path}"
Expand Down
42 changes: 42 additions & 0 deletions src/algos/math/complex.md
Original file line number Diff line number Diff line change
@@ -1 +1,43 @@
# 复数

### 创建复数
[num::complex::Complex](https://autumnai.github.io/cuticula/num/complex/struct.Complex.html) 可以帮助我们创建复数,其中实部和虚部必须是一样的类型。

```rust,editable
fn main() {
let complex_integer = num::complex::Complex::new(10, 20);
let complex_float = num::complex::Complex::new(10.1, 20.1);
println!("Complex integer: {}", complex_integer);
println!("Complex float: {}", complex_float);
}
```

### 复数相加
复数计算和 Rust 基本类型的计算并无区别。

```rust,editable
fn main() {
let complex_num1 = num::complex::Complex::new(10.0, 20.0); // Must use floats
let complex_num2 = num::complex::Complex::new(3.1, -4.2);
let sum = complex_num1 + complex_num2;
println!("Sum: {}", sum);
}
```

### 数学函数
[num::complex::Complex](https://autumnai.github.io/cuticula/num/complex/struct.Complex.html) 中定义了一些内置的数学函数,可用于对复数进行数学运算。

```rust,editable
use std::f64::consts::PI;
use num::complex::Complex;
fn main() {
let x = Complex::new(0.0, 2.0*PI);
println!("e^(2i * pi) = {}", x.exp()); // =~1
}
```

13 changes: 13 additions & 0 deletions theme/style.css → theme/style1.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
/* 修改滚动条宽度 */
::-webkit-scrollbar {
width: 5px;
height: 5px;
}

/* 表格靠左对齐 */
Expand Down Expand Up @@ -97,4 +98,16 @@ table {
/* Fix on mobile device */
code {
word-break: break-word;
}

/* 修复可编辑代码框顶部过窄的问题 */
code.editable, .ace_scroller {
top: 10px;
}

/* 修改书侧边目录的区域分隔行样式 */
.chapter .spacer {
background-color: #99CCFF;
height: 2px;
margin-top: 8px;
}

0 comments on commit 0880faa

Please sign in to comment.