Skip to content

Commit 5f1314f

Browse files
committed
Update README and add Fahrenheit to Celsius conversion function
1 parent 0e353f7 commit 5f1314f

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rfcalc"
3-
version = "0.3.3"
3+
version = "0.4.0"
44
edition = "2021"
55
authors = ["R4 Cheng <[email protected]>"]
66
license = "MIT"

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99

1010
## Usage
1111

12+
E.g.
13+
1214
- `rfcalc factorial <NUM>`: Calculate the factorial of a number (max: 20)
1315
- `rfcalc hw <NUM>`: Calculate the Hamming weight of a binary number
1416
- `rfcalc c <N> <K>`: Calculate the combination of `N` choose `K`
17+
- `rfcalc fc <NUM>`: Convert degree from Fahrenheit to Celsius
1518

1619
### `rfcalc bytes <expression to calculate>`
1720

src/calc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ pub fn calc_combination(n: u64, k: u64) -> u64 {
2727
numerator / denominator
2828
}
2929

30+
pub fn fahrenheit_to_celsius(f: f64) -> f64 {
31+
(f - 32.0) * 5.0 / 9.0
32+
}
33+
3034
/// B: byte
3135
#[derive(PartialEq, PartialOrd)]
3236
enum ByteUnit {

src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ enum Functions {
1818
C { n: u64, k: u64 },
1919
/// Calculate the difference in bytes by how many times
2020
Bytes { expression: String },
21+
/// Fahrenheit to Celsius
22+
FC { f: f64 },
2123
}
2224

2325
fn main() {
@@ -42,5 +44,9 @@ fn main() {
4244
let bytes = calc::devide_bytes(expression);
4345
println!("{}", bytes);
4446
}
47+
Functions::FC { f } => {
48+
let c = calc::fahrenheit_to_celsius(*f);
49+
println!("{}", c);
50+
}
4551
}
4652
}

0 commit comments

Comments
 (0)