MCPcopy Index your code
hub / github.com/RustPython/RustPython / format_complex_re_im

Method format_complex_re_im

crates/common/src/format.rs:873–899  ·  view source on GitHub ↗
(&self, num: &Complex64)

Source from the content-addressed store, hash-verified

871 }
872
873 fn format_complex_re_im(&self, num: &Complex64) -> Result<(String, String), FormatSpecError> {
874 // Format real part
875 let mut formatted_re = String::new();
876 if num.re != 0.0 || num.re.is_negative_zero() || self.format_type.is_some() {
877 let sign_re = if num.re.is_sign_negative() && !num.is_nan() {
878 "-"
879 } else {
880 match self.sign.unwrap_or(FormatSign::Minus) {
881 FormatSign::Plus => "+",
882 FormatSign::Minus => "",
883 FormatSign::MinusOrSpace => " ",
884 }
885 };
886 let re = self.format_complex_float(num.re)?;
887 formatted_re = format!("{sign_re}{re}");
888 }
889 // Format imaginary part
890 let sign_im = if num.im.is_sign_negative() && !num.im.is_nan() {
891 "-"
892 } else if formatted_re.is_empty() {
893 ""
894 } else {
895 "+"
896 };
897 let im = self.format_complex_float(num.im)?;
898 Ok((formatted_re, format!("{sign_im}{im}j")))
899 }
900
901 fn format_complex_float(&self, num: f64) -> Result<String, FormatSpecError> {
902 self.validate_format(FormatType::FixedPoint(Case::Lower))?;

Callers 2

format_complex_localeMethod · 0.80
format_complexMethod · 0.80

Calls 4

newFunction · 0.85
format_complex_floatMethod · 0.80
is_nanMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected