Continue work on separating complex types

This commit is contained in:
Austen Adler 2021-05-30 23:02:32 -04:00
parent c47287b4e6
commit dab0333b31

View File

@ -34,7 +34,7 @@ impl PartialEq for Number {
// pub value: Vec<Number>,
// }
#[derive(Copy, Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum Entry {
Number(Number),
@ -175,9 +175,15 @@ impl CalculatorEntry for Number {
fn format_entry(&self, display_mode: &CalculatorDisplayMode) -> String {
match display_mode {
CalculatorDisplayMode::Default => format!("{}", self.value),
CalculatorDisplayMode::Separated { separator } => separated(self.value, *separator),
CalculatorDisplayMode::Scientific { precision } => scientific(self.value, *precision),
CalculatorDisplayMode::Engineering { precision } => engineering(self.value, *precision),
CalculatorDisplayMode::Separated { separator } => {
separated(self.value, *separator)
}
CalculatorDisplayMode::Scientific { precision } => {
scientific(self.value, *precision)
}
CalculatorDisplayMode::Engineering { precision } => {
engineering(self.value, *precision)
}
CalculatorDisplayMode::Fixed { precision } => {
format!("{:0>.precision$}", self.value, precision = precision)
}
@ -246,7 +252,9 @@ impl CalculatorEntry for Number {
value: match angle_mode {
CalculatorAngleMode::Degrees => self.value.to_radians().sin(),
CalculatorAngleMode::Radians => self.value.sin(),
CalculatorAngleMode::Grads => (self.value * std::f64::consts::PI / 200.0).sin(),
CalculatorAngleMode::Grads => {
(self.value * std::f64::consts::PI / 200.0).sin()
}
},
}))
}
@ -255,7 +263,9 @@ impl CalculatorEntry for Number {
value: match angle_mode {
CalculatorAngleMode::Degrees => self.value.to_radians().cos(),
CalculatorAngleMode::Radians => self.value.cos(),
CalculatorAngleMode::Grads => (self.value * std::f64::consts::PI / 200.0).cos(),
CalculatorAngleMode::Grads => {
(self.value * std::f64::consts::PI / 200.0).cos()
}
},
}))
}
@ -264,7 +274,9 @@ impl CalculatorEntry for Number {
value: match angle_mode {
CalculatorAngleMode::Degrees => self.value.to_radians().tan(),
CalculatorAngleMode::Radians => self.value.tan(),
CalculatorAngleMode::Grads => (self.value * std::f64::consts::PI / 200.0).tan(),
CalculatorAngleMode::Grads => {
(self.value * std::f64::consts::PI / 200.0).tan()
}
},
}))
}
@ -273,7 +285,9 @@ impl CalculatorEntry for Number {
value: match angle_mode {
CalculatorAngleMode::Degrees => self.value.asin().to_degrees(),
CalculatorAngleMode::Radians => self.value.asin(),
CalculatorAngleMode::Grads => self.value.asin() * std::f64::consts::PI / 200.0,
CalculatorAngleMode::Grads => {
self.value.asin() * std::f64::consts::PI / 200.0
}
},
}))
}
@ -282,7 +296,9 @@ impl CalculatorEntry for Number {
value: match angle_mode {
CalculatorAngleMode::Degrees => self.value.acos().to_degrees(),
CalculatorAngleMode::Radians => self.value.acos(),
CalculatorAngleMode::Grads => self.value.acos() * std::f64::consts::PI / 200.0,
CalculatorAngleMode::Grads => {
self.value.acos() * std::f64::consts::PI / 200.0
}
},
}))
}
@ -291,7 +307,9 @@ impl CalculatorEntry for Number {
value: match angle_mode {
CalculatorAngleMode::Degrees => self.value.atan().to_degrees(),
CalculatorAngleMode::Radians => self.value.atan(),
CalculatorAngleMode::Grads => self.value.atan() * std::f64::consts::PI / 200.0,
CalculatorAngleMode::Grads => {
self.value.atan() * std::f64::consts::PI / 200.0
}
},
}))
}