(
left: &ast::Number,
op: &ast::Operator,
right: &ast::Number,
)
| 712 | |
| 713 | #[cfg(feature = "parser")] |
| 714 | fn 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")] |
| 740 | fn number_to_complex(number: &ast::Number) -> Option<(f64, f64, bool)> { |
no test coverage detected