pub fn adaptive_mul(
    lhs: &PrimitiveArray<i128>,
    rhs: &PrimitiveArray<i128>
) -> Result<PrimitiveArray<i128>>
Available on crate feature compute_arithmetics only.
Expand description

Adaptive multiplication of two decimal primitive arrays with different precision and scale. If the precision and scale is different, then the smallest scale and precision is adjusted to the largest precision and scale. If during the multiplication one of the results is larger than the max possible value, the result precision is changed to the precision of the max value

  11111.0    -> 6, 1
     10.002  -> 5, 3
-----------------
 111132.222  -> 9, 3

Examples

use arrow2::compute::arithmetics::decimal::adaptive_mul;
use arrow2::array::PrimitiveArray;
use arrow2::datatypes::DataType;

let a = PrimitiveArray::from([Some(11111_0i128), Some(1_0i128)]).to(DataType::Decimal(6, 1));
let b = PrimitiveArray::from([Some(10_002i128), Some(2_000i128)]).to(DataType::Decimal(5, 3));
let result = adaptive_mul(&a, &b).unwrap();
let expected = PrimitiveArray::from([Some(111132_222i128), Some(2_000i128)]).to(DataType::Decimal(9, 3));

assert_eq!(result, expected);