Skip to main content

interval_mul_f64

Function interval_mul_f64 

Source
fn interval_mul_f64(
    interval: IntervalMonthDayNano,
    factor: f64,
) -> Result<IntervalMonthDayNano, ArrowError>
Expand description

Multiplies an IntervalMonthDayNano by an f64, mirroring DuckDB’s interval_t layout of months, days, and a sub-day component (nanoseconds in Arrow, microseconds in DuckDB). https://github.com/duckdb/duckdb/blob/21aca0424f1faf78b593b1e6fbfdd4846624c987/src/include/duckdb/common/types/interval.hpp#L24-L27

Algorithm:

  1. use checked integer multiplication when factor fits in i64 (early return).
  2. multiply months and days separately
  3. cascade remainders: convert fractional months to days using 30 days per month, then fractional days to a sub-day value using 24 hours per day.
  4. combine the cascaded remainder with the scaled input nanoseconds and round ties-to-even at nanosecond precision.
  5. return an overflow error if any output component is out of range.