Divides two arrays element-wise. You can also use the / operator.
Like base R's /, this is a true division: integer and boolean operands are converted
to the default float before dividing, so 7L / 2L is
3.5. Use nv_floor_div() (%/%) for integer division.
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 aslhsandrhs.
Value
(arrayish)
Has the inputs' broadcast shape and their common data type, or the default
float when that is not a float type.
See also
prim_div() for the underlying primitive, which divides integers
with truncation.
Examples
x <- nv_array(c(10, 20, 30))
y <- nv_array(c(2, 5, 10))
nv_div(x, y)
#> AnvlArray
#> 5
#> 4
#> 3
#> [ CPUf32{3} ]
x / y
#> AnvlArray
#> 5
#> 4
#> 3
#> [ CPUf32{3} ]
# different data types are promoted to their common one
nv_div(nv_scalar(10, "f32"), nv_scalar(4, "f64"))
#> AnvlArray
#> 2.5000
#> [ CPUf64{} ]
# a scalar is broadcast and an R integer is converted to a float
x / 2L
#> AnvlArray
#> 5
#> 10
#> 15
#> [ CPUf32{3} ]
# integers are divided as floats
nv_array(c(7L, -7L)) / 2L
#> AnvlArray
#> 3.5000
#> -3.5000
#> [ CPUf32{2} ]