mirror of
https://github.com/PaddiM8/kalker.git
synced 2024-12-13 10:00:51 +01:00
Finding square roots for estimate()
This commit is contained in:
parent
34e374b346
commit
0bbf1c4974
@ -377,7 +377,7 @@ impl KalkNum {
|
||||
|
||||
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 output.len() > 0 {
|
||||
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
|
||||
let rounded = self.round_one_value(complex_number_type)?.to_string();
|
||||
Some(trim_zeroes(&rounded))
|
||||
|
Loading…
Reference in New Issue
Block a user