mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-01-31 08:59:15 +01:00
Finding square roots for estimate()
This commit is contained in:
parent
9fa19cb770
commit
8827b03f2e
@ -377,7 +377,7 @@ impl KalkNum {
|
|||||||
|
|
||||||
output.push_str(&format!("{}i", value));
|
output.push_str(&format!("{}i", value));
|
||||||
}
|
}
|
||||||
} else if self.has_real() {
|
} else if self.has_imaginary() {
|
||||||
// If there is a real value as well
|
// If there is a real value as well
|
||||||
if output.len() > 0 {
|
if output.len() > 0 {
|
||||||
output.push_str(" + ");
|
output.push_str(" + ");
|
||||||
@ -473,6 +473,14 @@ impl KalkNum {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the value squared (and rounded) is an integer,
|
||||||
|
// eg. x² is an integer,
|
||||||
|
// then it can be expressed as sqrt(x²)
|
||||||
|
let squared = KalkNum::new(value.clone() * value, "").round_if_needed();
|
||||||
|
if squared.value.clone().fract() == 0f64 {
|
||||||
|
return Some(format!("√{}", squared.to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
// If nothing above was relevant, simply round it off a bit, eg. from 0.99999 to 1
|
// If nothing above was relevant, simply round it off a bit, eg. from 0.99999 to 1
|
||||||
let rounded = self.round_one_value(complex_number_type)?.to_string();
|
let rounded = self.round_one_value(complex_number_type)?.to_string();
|
||||||
Some(trim_zeroes(&rounded))
|
Some(trim_zeroes(&rounded))
|
||||||
|
Loading…
Reference in New Issue
Block a user