pub fn add(
lhs: &PrimitiveArray<i128>,
rhs: &PrimitiveArray<i128>
) -> PrimitiveArray<i128>
Expand description
Adds two decimal PrimitiveArray
with the same precision and scale.
Error
Errors if the precision and scale are different.
Panic
This function panics iff the added numbers result in a number larger than the possible number for the precision.
Examples
use arrow2::compute::arithmetics::decimal::add;
use arrow2::array::PrimitiveArray;
use arrow2::datatypes::DataType;
let a = PrimitiveArray::from([Some(1i128), Some(1i128), None, Some(2i128)]).to(DataType::Decimal(5, 2));
let b = PrimitiveArray::from([Some(1i128), Some(2i128), None, Some(2i128)]).to(DataType::Decimal(5, 2));
let result = add(&a, &b);
let expected = PrimitiveArray::from([Some(2i128), Some(3i128), None, Some(4i128)]).to(DataType::Decimal(5, 2));
assert_eq!(result, expected);