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

Method format_complex

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

Source from the content-addressed store, hash-verified

854 }
855
856 pub fn format_complex(&self, num: &Complex64) -> Result<String, FormatSpecError> {
857 let (formatted_re, formatted_im) = self.format_complex_re_im(num)?;
858 // Enclose in parentheses if there is no format type and formatted_re is not empty
859 let magnitude_str = if self.format_type.is_none() && !formatted_re.is_empty() {
860 format!("({formatted_re}{formatted_im})")
861 } else {
862 format!("{formatted_re}{formatted_im}")
863 };
864 if let Some(FormatAlign::AfterSign) = &self.align {
865 return Err(FormatSpecError::AlignmentFlag);
866 }
867 match &self.fill.unwrap_or(' '.into()).to_char() {
868 Some('0') => Err(FormatSpecError::ZeroPadding),
869 _ => self.format_sign_and_align(&AsciiStr::new(&magnitude_str), "", FormatAlign::Right),
870 }
871 }
872
873 fn format_complex_re_im(&self, num: &Complex64) -> Result<(String, String), FormatSpecError> {
874 // Format real part

Callers 1

__format__Method · 0.80

Calls 7

newFunction · 0.85
format_complex_re_imMethod · 0.80
format_sign_and_alignMethod · 0.80
ErrClass · 0.50
is_noneMethod · 0.45
is_emptyMethod · 0.45
to_charMethod · 0.45

Tested by

no test coverage detected