Fixed estimation skipping values with no estimation, when the real/complex value had an estimation

This commit is contained in:
bakk 2021-05-23 00:52:43 +02:00
parent c80f58433c
commit 7b635079c8

View File

@ -92,6 +92,10 @@ impl ScientificNotation {
} }
impl KalkNum { impl KalkNum {
pub fn has_real(&self) -> bool {
self.value != 0f64
}
pub fn has_imaginary(&self) -> bool { pub fn has_imaginary(&self) -> bool {
self.imaginary_value != 0f64 self.imaginary_value != 0f64
} }
@ -355,6 +359,8 @@ impl KalkNum {
let mut output = String::new(); let mut output = String::new();
if let Some(value) = rounded_real { if let Some(value) = rounded_real {
output.push_str(&value); output.push_str(&value);
} else if self.has_real() {
output.push_str(&self.to_string_real());
} }
if let Some(value) = rounded_imaginary { if let Some(value) = rounded_imaginary {
@ -371,6 +377,13 @@ impl KalkNum {
output.push_str(&format!("{}i", value)); output.push_str(&format!("{}i", value));
} }
} else if self.has_real() {
// If there is a real value as well
if output.len() > 0 {
output.push_str(" + ");
}
output.push_str(&self.to_string_imaginary(true));
} }
Some(output) Some(output)