Function polars::export::arrow::compute::arithmetics::decimal::adaptive_add
source · [−]pub fn adaptive_add(
lhs: &PrimitiveArray<i128>,
rhs: &PrimitiveArray<i128>
) -> Result<PrimitiveArray<i128>, ArrowError>
This is supported on crate feature
compute_arithmetics
only.Expand description
Adaptive addition 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 larger than the max possible value, the result precision is changed to the precision of the max value
11111.11 -> 7, 2
11111.111 -> 8, 3
------------------
22222.221 -> 8, 3
Examples
use arrow2::compute::arithmetics::decimal::adaptive_add;
use arrow2::array::PrimitiveArray;
use arrow2::datatypes::DataType;
let a = PrimitiveArray::from([Some(11111_11i128)]).to(DataType::Decimal(7, 2));
let b = PrimitiveArray::from([Some(11111_111i128)]).to(DataType::Decimal(8, 3));
let result = adaptive_add(&a, &b).unwrap();
let expected = PrimitiveArray::from([Some(22222_221i128)]).to(DataType::Decimal(8, 3));
assert_eq!(result, expected);