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

Adaptive subtract 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 addition one of the results is smaller than the min possible value, the result precision is changed to the precision of the min value

 99.9999 -> 6, 4
-00.0001 -> 6, 4
-----------------
100.0000 -> 7, 4

Examples

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

let a = PrimitiveArray::from([Some(99_9999i128)]).to(DataType::Decimal(6, 4));
let b = PrimitiveArray::from([Some(-00_0001i128)]).to(DataType::Decimal(6, 4));
let result = adaptive_sub(&a, &b).unwrap();
let expected = PrimitiveArray::from([Some(100_0000i128)]).to(DataType::Decimal(7, 4));

assert_eq!(result, expected);