Skip to contents

Element-wise flooring remainder of division. The sign of the result equals the sign of rhs, matching base R's %% operator.

Usage

nv_mod(lhs, rhs)

# S3 method for class 'AnvlArray'
e1%%e2

Arguments

lhs, rhs

(arrayish)
Two inputs with a common data type. Can be any numeric data type. Scalars are broadcast. An R value takes the other operand's data type when that is in its own or a higher category. Otherwise it settles on its default data type, and the operands meet at their common data type.

e1, e2

(arrayish)
The operands of the operator, which it passes on as lhs and rhs.

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} ]