Divide this interval by the given interval (`other`). Say we have intervals `[a1, b1]` and `[a2, b2]`, then their division is `[a1, b1] * [1 / b2, 1 / a2]` if `0 ∉ [a2, b2]` and `[NEG_INF, INF]` otherwise. Note that this represents all possible values the quotient can take if one can choose single values arbitrarily from each of the operands. If the two intervals have different data types, both a
(&self, other: T)
| 849 | /// **TODO**: Once interval sets are supported, cases where the divisor contains |
| 850 | /// zero should result in an interval set, not the universal set. |
| 851 | pub fn div<T: Borrow<Self>>(&self, other: T) -> Result<Self> { |
| 852 | let rhs = other.borrow(); |
| 853 | let (lhs_owned, rhs_owned, dt) = coerce_operands(self, rhs, &Operator::Divide)?; |
| 854 | let lhs_ref = lhs_owned.as_ref().unwrap_or(self); |
| 855 | let rhs_ref = rhs_owned.as_ref().unwrap_or(rhs); |
| 856 | |
| 857 | let zero = ScalarValue::new_zero(&dt)?; |
| 858 | // We want 0 to be approachable from both negative and positive sides. |
| 859 | let zero_point = match &dt { |
| 860 | DataType::Float32 | DataType::Float64 => Self::new(zero.clone(), zero), |
| 861 | _ => Self::new(prev_value(zero.clone()), next_value(zero)), |
| 862 | }; |
| 863 | |
| 864 | // Exit early with an unbounded interval if zero is strictly inside the |
| 865 | // right hand side: |
| 866 | if rhs_ref.contains(&zero_point)? == Self::TRUE && !dt.is_unsigned_integer() { |
| 867 | Self::make_unbounded(&dt) |
| 868 | } |
| 869 | // At this point, we know that only one endpoint of the right hand side |
| 870 | // can be zero. |
| 871 | else if lhs_ref.contains(&zero_point)? == Self::TRUE |
| 872 | && !dt.is_unsigned_integer() |
| 873 | { |
| 874 | Ok(div_helper_lhs_zero_inclusive( |
| 875 | &dt, |
| 876 | lhs_ref, |
| 877 | rhs_ref, |
| 878 | &zero_point, |
| 879 | )) |
| 880 | } else { |
| 881 | Ok(div_helper_zero_exclusive( |
| 882 | &dt, |
| 883 | lhs_ref, |
| 884 | rhs_ref, |
| 885 | &zero_point, |
| 886 | )) |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | /// Computes the width of this interval; i.e. the difference between its |
| 891 | /// bounds. For unbounded intervals, this function will return a `NULL` |