Skip to content

Commit

Permalink
Update README and add Fahrenheit to Celsius conversion function
Browse files Browse the repository at this point in the history
  • Loading branch information
chengr4 committed Sep 11, 2024
1 parent 0e353f7 commit 5f1314f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rfcalc"
version = "0.3.3"
version = "0.4.0"
edition = "2021"
authors = ["R4 Cheng <[email protected]>"]
license = "MIT"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

## Usage

E.g.

- `rfcalc factorial <NUM>`: Calculate the factorial of a number (max: 20)
- `rfcalc hw <NUM>`: Calculate the Hamming weight of a binary number
- `rfcalc c <N> <K>`: Calculate the combination of `N` choose `K`
- `rfcalc fc <NUM>`: Convert degree from Fahrenheit to Celsius

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

Expand Down
4 changes: 4 additions & 0 deletions src/calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ pub fn calc_combination(n: u64, k: u64) -> u64 {
numerator / denominator
}

pub fn fahrenheit_to_celsius(f: f64) -> f64 {
(f - 32.0) * 5.0 / 9.0
}

/// B: byte
#[derive(PartialEq, PartialOrd)]
enum ByteUnit {
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ enum Functions {
C { n: u64, k: u64 },
/// Calculate the difference in bytes by how many times
Bytes { expression: String },
/// Fahrenheit to Celsius
FC { f: f64 },
}

fn main() {
Expand All @@ -42,5 +44,9 @@ fn main() {
let bytes = calc::devide_bytes(expression);
println!("{}", bytes);
}
Functions::FC { f } => {
let c = calc::fahrenheit_to_celsius(*f);
println!("{}", c);
}
}
}

0 comments on commit 5f1314f

Please sign in to comment.