Re: [PATCH v5 3/3] rust: math: add signed division and remainder helpers

From: FUJITA Tomonori

Date: Sat Oct 31 2026 - 07:58:56 EST


On Sat, 31 Oct 2026 18:32:06 +0800
chenhan <chenhan0017.work@xxxxxxxxx> wrote:

> Delta's division and remainder implementations operate on integers and
> do not depend on time units. Move them into a math module to provide a
> common home for arithmetic helpers, with Delta as the initial user.
>
> Expose div64_s64() for an i64 dividend and divisor, and div_s64_rem()
> for an i64 dividend and an i32 divisor. The latter returns an i64 quotient
> and an i32 remainder, matching the results of the C helper without
> exposing its output pointer. Delta's rem_nanos() uses the remainder and
> converts it to i64. Both helpers retain Rust's signed operator semantics
> and unconditional panic checks, using the existing C helpers on 32-bit.
>
> Keep the Delta API and its panic conditions unchanged. Document the
> quotient and remainder semantics and link to the corresponding C header.
> This is separate from the preceding behavior fix so that introducing
> the math module is not required for a backport.
>
> Assisted-by: LLM
> Signed-off-by: chenhan <chenhan0017.work@xxxxxxxxx>

Reviewed-by: FUJITA Tomonori <fujita.tomonori@xxxxxxxxx>

Two nits, only if you respin for other reasons:

The second sentence of the SAFETY comment in div_s64_rem() could be
shorter. The old comment in time.rs said enough:

// SAFETY: `rem` is in the stack, so we can always provide a valid
// pointer to it.

The helpers have no examples. A doctest for each would also run as a
KUnit test for the valid inputs on both 32-bit and 64-bit.