(&self, sum: T::Native, count: T::Native)
| 155 | /// * count: total count, stored as a i128/i256 (*NOT* a Decimal128/Decimal256 value) |
| 156 | #[inline(always)] |
| 157 | pub fn avg(&self, sum: T::Native, count: T::Native) -> Result<T::Native> { |
| 158 | if let Ok(value) = sum.mul_checked(self.target_mul.div_wrapping(self.sum_mul)) { |
| 159 | let new_value = value.div_wrapping(count); |
| 160 | |
| 161 | let validate = T::validate_decimal_precision( |
| 162 | new_value, |
| 163 | self.target_precision, |
| 164 | self.target_scale, |
| 165 | ); |
| 166 | |
| 167 | if validate.is_ok() { |
| 168 | Ok(new_value) |
| 169 | } else { |
| 170 | exec_err!("Arithmetic Overflow in AvgAccumulator") |
| 171 | } |
| 172 | } else { |
| 173 | // can't convert the lit decimal to the returned data type |
| 174 | exec_err!("Arithmetic Overflow in AvgAccumulator") |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | /// Generic way to collect distinct values for accumulators. |
no test coverage detected