Skip to content

Add decimal arithmetic kernels with checked overflow and auto-promotion + fix null mask drop on broadcasting - #185

Merged
pbower merged 4 commits into
feature/decimalfrom
MA-EPC86-DECIMAL-TSK381-KERNELS
Aug 31, 2026
Merged

Add decimal arithmetic kernels with checked overflow and auto-promotion + fix null mask drop on broadcasting#185
pbower merged 4 commits into
feature/decimalfrom
MA-EPC86-DECIMAL-TSK381-KERNELS

Conversation

@pbower

@pbower pbower commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • New src/kernels/arithmetic/decimal.rs module with checked binary ops (add, subtract, multiply, divide, remainder), unary ops (negate, abs), rescale, and comparison kernels
  • Decimal dispatch arms in arithmetic_dispatch and scalar_arithmetic for all three widths
  • Cross-scale reconciliation: different-scale operands rescale to the finer scale before computing
  • Auto-promotion: integer+decimal promotes to decimal, float+decimal promotes to Float64, mixed-width decimals widen to the wider type
  • Overflow detection returns MinarrowError via new KernelError::Overflow variant
  • Division by zero produces null (consistent with float division semantics)
  • 39 tests covering same-scale, cross-scale, width promotion, auto-promotion, overflow, null propagation

Test plan

  • cargo test --features decimal passes (814 tests)
  • cargo test --all-features passes (1711 tests)
  • cargo test without decimal passes (no regression)

pbower added 2 commits August 31, 2026 05:46
Decimal arithmetic uses checked operations instead of wrapping to
prevent silent corruption of exact-precision values. Scale
reconciliation, result-precision computation, and cross-type promotion
are handled at the kernel level so callers pass DecimalArray pairs and
receive correctly-typed results.

Kernel operations:
- Add/subtract with same-scale and cross-scale reconciliation
- Multiply with result scale = s1 + s2
- Divide with numerator scale-up for fractional-digit preservation
- Remainder with scale reconciliation
- Negate and abs (unary, checked)
- Rescale to a new scale (up via checked multiply, down via truncation)
- Element-wise comparison (eq, lt, gt, le, ge, ne) with cross-scale support

Dispatch routing (arithmetic_dispatch):
- Same-type Decimal32/64/128 arithmetic
- Cross-width promotion (Decimal32+Decimal64 widens to Decimal64, etc.)
- Integer + Decimal auto-promotion (integer scaled to decimal)
- Float + Decimal auto-promotion (decimal converted to Float64)
- Overflow returns MinarrowError rather than wrapping
- Length-1 decimal broadcast for scalar expansion

Also adds KernelError::Overflow variant for checked-arithmetic failures
and decimal scalar arithmetic arms for Scalar + Scalar operations.
- Fix overflow error variant and module doc wording
- Add arr_dec32!, arr_dec64!, arr_dec128! macros to array.rs
- Replace test helper functions with macro imports
- Remove bracketed asides from comments
@pbower
pbower force-pushed the MA-EPC86-DECIMAL-TSK381-KERNELS branch from 90ea29e to e4de091 Compare August 31, 2026 06:07
pbower added 2 commits August 31, 2026 07:13
The existing integer, float, boolean, and string broadcast arms
discarded null status when repeating a length-1 array. Now all arms
check the source element's null mask and broadcast it accordingly.
@pbower pbower changed the title Add decimal arithmetic kernels with checked overflow and auto-promotion (TSK381) Add decimal arithmetic kernels with checked overflow and auto-promotion + fix null mask drop on broadcasting Aug 31, 2026
@pbower
pbower merged commit 6c8eba0 into feature/decimal Aug 31, 2026
12 of 17 checks passed
@pbower
pbower deleted the MA-EPC86-DECIMAL-TSK381-KERNELS branch August 31, 2026 06:28
pbower added a commit that referenced this pull request Aug 31, 2026
* Add DecimalArray foundation and i128 trait impls (#181)

* Add Decimal32, Decimal64, Decimal128 variants to ArrowType (#180)

* Wire DecimalArray into NumericArray, Array, Scalar with From impls (#182)

* Wire DecimalArray into NumericArray, Array, and Scalar enums with From impls and tests (#182)

* Implement decimal conversion arms in NumericArray try_ accessors

* Add decimal FFI import/export with arrow-rs and Polars round-trips (#186)

* Add decimal FFI import/export with arrow-rs and Polars round-trips

* Integrate DecimalArray into Value, ArrayV, NumericArrayV, SuperArray, SuperArrayV, and Consolidate (#187)

* Add decimal broadcast dispatch and scale-aware print formatting (#184)

* Add decimal arithmetic kernels with checked overflow and auto-promotion + fix null mask drop on broadcasting (#185)

* Add decimal arithmetic kernels with checked overflow and auto-promotion
* Propagate null mask through broadcast for all array types

* Add DecimalArray type conversions and width conversion methods (#183)

* Add decimal support to pyo3 and minarrow-py Python bridges (#188)

* Add Decimal32 and Decimal64 round-trip tests for arrow-rs

* Add decimal support to pyo3 and minarrow-py Python bridges

* Make precision and scale report values for all numeric types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant