Multiply the given interval (`other`) with this interval. Say we have intervals `[a1, b1]` and `[a2, b2]`, then their product is `[min(a1 * a2, a1 * b2, b1 * a2, b1 * b2), max(a1 * a2, a1 * b2, b1 * a2, b1 * b2)]`. Note that this represents all possible values the product can take if one can choose single values arbitrarily from each of the operands. If the two intervals have different data types
(&self, other: T)
| 813 | /// If the two intervals have different data types, both are coerced to a |
| 814 | /// common type via [`BinaryTypeCoercer`] before computing the product. |
| 815 | pub fn mul<T: Borrow<Self>>(&self, other: T) -> Result<Self> { |
| 816 | let rhs = other.borrow(); |
| 817 | let (lhs_owned, rhs_owned, dt) = coerce_operands(self, rhs, &Operator::Multiply)?; |
| 818 | let lhs_ref = lhs_owned.as_ref().unwrap_or(self); |
| 819 | let rhs_ref = rhs_owned.as_ref().unwrap_or(rhs); |
| 820 | |
| 821 | let zero = ScalarValue::new_zero(&dt)?; |
| 822 | |
| 823 | let result = match ( |
| 824 | lhs_ref.contains_value(&zero)?, |
| 825 | rhs_ref.contains_value(&zero)?, |
| 826 | dt.is_unsigned_integer(), |
| 827 | ) { |
| 828 | (true, true, false) => mul_helper_multi_zero_inclusive(&dt, lhs_ref, rhs_ref), |
| 829 | (true, false, false) => { |
| 830 | mul_helper_single_zero_inclusive(&dt, lhs_ref, rhs_ref, &zero) |
| 831 | } |
| 832 | (false, true, false) => { |
| 833 | mul_helper_single_zero_inclusive(&dt, rhs_ref, lhs_ref, &zero) |
| 834 | } |
| 835 | _ => mul_helper_zero_exclusive(&dt, lhs_ref, rhs_ref, &zero), |
| 836 | }; |
| 837 | Ok(result) |
| 838 | } |
| 839 | |
| 840 | /// Divide this interval by the given interval (`other`). Say we have intervals |
| 841 | /// `[a1, b1]` and `[a2, b2]`, then their division is `[a1, b1] * [1 / b2, 1 / a2]` |