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

Function fold_number_binop

crates/vm/src/stdlib/_ast.rs:714–737  ·  view source on GitHub ↗
(
    left: &ast::Number,
    op: &ast::Operator,
    right: &ast::Number,
)

Source from the content-addressed store, hash-verified

712
713#[cfg(feature = "parser")]
714fn fold_number_binop(
715 left: &ast::Number,
716 op: &ast::Operator,
717 right: &ast::Number,
718) -> Option<ast::Number> {
719 let (left_real, left_imag, left_is_complex) = number_to_complex(left)?;
720 let (right_real, right_imag, right_is_complex) = number_to_complex(right)?;
721
722 if !(left_is_complex || right_is_complex) {
723 return None;
724 }
725
726 match op {
727 ast::Operator::Add => Some(ast::Number::Complex {
728 real: left_real + right_real,
729 imag: left_imag + right_imag,
730 }),
731 ast::Operator::Sub => Some(ast::Number::Complex {
732 real: left_real - right_real,
733 imag: left_imag - right_imag,
734 }),
735 _ => None,
736 }
737}
738
739#[cfg(feature = "parser")]
740fn number_to_complex(number: &ast::Number) -> Option<(f64, f64, bool)> {

Callers 1

fold_exprFunction · 0.85

Calls 2

number_to_complexFunction · 0.85
SomeClass · 0.50

Tested by

no test coverage detected