typst::foundations::calc

Function rem_euclid

source
pub fn rem_euclid(
    span: Span,
    dividend: DecNum,
    divisor: Spanned<DecNum>,
) -> SourceResult<DecNum>
Expand description

This calculates the least nonnegative remainder of a division.

Warning: Due to a floating point round-off error, the remainder may equal the absolute value of the divisor if the dividend is much smaller in magnitude than the divisor and the dividend is negative. This only applies for floating point inputs.

In addition, this can error if given a [decimal] input and the dividend is too small in magnitude compared to the divisor.

#calc.rem-euclid(7, 3) \
#calc.rem-euclid(7, -3) \
#calc.rem-euclid(-7, 3) \
#calc.rem-euclid(-7, -3) \
#calc.rem-euclid(1.75, 0.5) \
#calc.rem-euclid(decimal("1.75"), decimal("0.5"))