Skip to contents

Element-wise remainder. The result has the sign of the dividend, which is what StableHLO's remainder does. Base R's %% takes the sign of the divisor instead and is available via nv_mod().

Usage

prim_remainder(x, y)

Arguments

x, y

(arrayish)
Two inputs of the same data type and shape. Can be any numeric data type. R values take the other operand's data type when it is in their data type category, and their default data type when neither operand has one. An R value outside the other operand's category is an error, as are two R values of different storage types.

Value

(arrayish)
Has the inputs' shape and data type.

Implemented Rules

  • stablehlo

  • reverse

StableHLO

Lowers to hlo_remainder(), specified under remainder.

See also

Examples

# two R values: both take an R double's default data type
prim_remainder(1, -3)
#> AnvlArray
#>  1
#> [ CPUf32{} ] 

# the R value is built at the array's data type instead
prim_remainder(1, nv_scalar(-3, "f64"))
#> AnvlArray
#>  1
#> [ CPUf64{} ] 

# the sign follows the dividend, where base R's %% follows the divisor
1 %% -3
#> [1] -2