mirror of
https://github.com/PaddiM8/kalker.git
synced 2024-12-12 17:40:52 +01:00
Show NaN and inf in a more user-friendly way
This commit is contained in:
parent
b6412aca1e
commit
6d88da749d
@ -186,6 +186,16 @@ impl KalkNum {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_string_pretty(&self) -> String {
|
pub fn to_string_pretty(&self) -> String {
|
||||||
|
let real_f64 = self.to_f64();
|
||||||
|
let imaginary_f64 = self.imaginary_to_f64();
|
||||||
|
if real_f64.is_nan() || imaginary_f64.is_nan() {
|
||||||
|
return String::from("Not defined.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if real_f64.is_infinite() {
|
||||||
|
return format!("{}∞", if real_f64.is_sign_negative() { "-" } else { "" });
|
||||||
|
}
|
||||||
|
|
||||||
let sci_notation_real = self.to_scientific_notation(ComplexNumberType::Real);
|
let sci_notation_real = self.to_scientific_notation(ComplexNumberType::Real);
|
||||||
let mut adjusted_num = self.clone();
|
let mut adjusted_num = self.clone();
|
||||||
let result_str = if (-6..8).contains(&sci_notation_real.exponent) || self.value == 0f64 {
|
let result_str = if (-6..8).contains(&sci_notation_real.exponent) || self.value == 0f64 {
|
||||||
|
Loading…
Reference in New Issue
Block a user