aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/input.rs14
-rw-r--r--src/lib.rs27
2 files changed, 25 insertions, 16 deletions
diff --git a/src/input.rs b/src/input.rs
index ab4a1d1..2f9d820 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -12,17 +12,17 @@ impl Calculator {
_ => {}
},
KeyModifiers::SHIFT => match key.code {
- KeyCode::Char('D') => self.clear(),
- _ => {}
- },
- KeyModifiers::NONE => match key.code {
- KeyCode::Char('q') => {
+ KeyCode::Char('Q') => {
return Signal::Exit;
}
- KeyCode::Char('j' | 'k') => self.swap(),
- KeyCode::Char('d') => {
+ KeyCode::Char('J' | 'K') => self.swap(),
+ KeyCode::Char('D') => {
self.input_buffer = String::new();
}
+ KeyCode::Char('C') => self.clear(),
+ _ => {}
+ },
+ KeyModifiers::NONE => match key.code {
KeyCode::Char(c) => self.push_to_buffer(c),
KeyCode::Backspace => {
self.input_buffer.pop();
diff --git a/src/lib.rs b/src/lib.rs
index 537d876..97d3fa9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -55,26 +55,35 @@ impl Operator {
struct ParseOperatorError(char);
enum Function {
- Sin,
- Cos,
- Tan,
+ DSin, // Sine (degrees)
+ DCos, // Cosine (degrees)
+ DTan, // Tangent (degrees)
+ RSin, // Sine (radians)
+ RCos, // Cosing (radians)
+ RTan, // Tangent (radians)
}
impl Function {
fn parse(s: &str) -> Result<Self, ParseFunctionError> {
match s {
- "sin" => Ok(Self::Sin),
- "cos" => Ok(Self::Cos),
- "tan" => Ok(Self::Tan),
+ "dsin" => Ok(Self::DSin),
+ "dcos" => Ok(Self::DCos),
+ "dtan" => Ok(Self::DTan),
+ "rsin" => Ok(Self::RSin),
+ "rcos" => Ok(Self::RCos),
+ "rtan" => Ok(Self::RTan),
_ => Err(ParseFunctionError(s.to_string())),
}
}
fn call_on(&self, f: f64) -> f64 {
match self {
- Self::Sin => f.sin(),
- Self::Cos => f.cos(),
- Self::Tan => f.tan(),
+ Self::DSin => f.to_radians().sin(),
+ Self::DCos => f.to_radians().cos(),
+ Self::DTan => f.to_radians().tan(),
+ Self::RSin => f.sin(),
+ Self::RCos => f.cos(),
+ Self::RTan => f.tan(),
}
}
}