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

Saturated subtraction of two decimal primitive arrays with the same precision and scale. If the precision and scale is different, then an InvalidArgumentError is returned. If the result from the sum is smaller than the possible number with the selected precision then the resulted number in the arrow array is the minimum number for the selected precision.

Examples

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

let a = PrimitiveArray::from([Some(-99000i128), Some(11100i128), None, Some(22200i128)]).to(DataType::Decimal(5, 2));
let b = PrimitiveArray::from([Some(01000i128), Some(22200i128), None, Some(11100i128)]).to(DataType::Decimal(5, 2));

let result = saturating_sub(&a, &b);
let expected = PrimitiveArray::from([Some(-99999i128), Some(-11100i128), None, Some(11100i128)]).to(DataType::Decimal(5, 2));

assert_eq!(result, expected);