Skip to main content

Module decimal

Module decimal 

Source
Expand description

Exact decimal string → scaled integer conversion (roadmap §12).

The rule from the roadmap: never convert decimal through f64.

Arrow Decimal128 stores a value as i128 * 10^(-scale). So to represent “123.45” in Decimal128(18, 2) we need i128 = 12345.

This module converts a DB text-protocol decimal string to the scaled integer Arrow needs without ever touching floating-point arithmetic — i128 for Decimal128 (precision ≤ 38) and i256 for Decimal256 (precision 39–76).

Functions§

decimal_str_to_scaled_i128
decimal_str_to_scaled_i256
Decimal256 analogue of decimal_str_to_scaled_i128 — parses straight into i256 so values beyond i128 (precision 39–76) are not truncated. Returns None for empty / non-numeric strings or i256 overflow.
scale_int_to_i256
Scale an integer (already widened to i128) by 10^scale into i256 — the Decimal256 analogue of the source drivers’ scale_int_to_i128. None on negative scale or i256 overflow.
scaled_i128_to_decimal_str
Convert a decimal string (as returned by the database text protocol) to a scaled i128 ready to be stored in an Arrow Decimal128 array.