Element-wise flooring remainder of division. The sign of the result equals the sign of rhs, matching base R's %%
operator.
Arguments
- lhs, rhs
(
arrayish)
Two inputs with a common data type. Can be any numeric data type. Scalars are broadcast, and R values assume the other operand's data type within their data type category, otherwise falling back to their default data type and being converted to the common data type.
Value
(arrayish)
Has the inputs' broadcast shape and common data type.
See also
nv_remainder() for truncating remainder, nv_floor_div() for the
matching division, prim_remainder() for the underlying primitive.
Examples
x <- nv_array(c(1L, -1L))
y <- nv_array(c(-3L, 3L))
nv_mod(x, y)
#> AnvlArray
#> -2
#> 2
#> [ CPUi32{2} ]
as.vector(x) %% as.vector(y)
#> [1] -2 2
# different data types are promoted to their common one
nv_mod(nv_scalar(1L, "i32"), nv_scalar(-3L, "i64"))
#> AnvlArray
#> -2
#> [ CPUi64{} ]
# a scalar is broadcast
x %% 2L
#> AnvlArray
#> 1
#> 1
#> [ CPUi32{2} ]