Skip to contents

Rounds the elements of an array to the nearest integer.

Usage

prim_round(x, method = "nearest_even")

Arguments

x

(arrayish)
One input. Can be any float data type. An R value materializes at its default data type.

method

(character(1))
Rounding method. "nearest_even" (default) rounds to the nearest even integer on a tie, "afz" rounds away from zero on a tie.

Value

(arrayish)
Has x's data type and shape.

Implemented Rules

  • stablehlo

  • reverse

StableHLO

Lowers to hlo_round_nearest_even(), specified under round_nearest_even. With method = "afz" it lowers to hlo_round_nearest_afz() instead, specified under round_nearest_afz.

See also

Examples

# the input's data type carries through
x <- nv_array(c(1.4, 2.5, 3.6))
prim_round(x)
#> AnvlArray
#>  1
#>  2
#>  4
#> [ CPUf32{3} ] 

# an R value materializes at its default data type
prim_round(2.5)
#> AnvlArray
#>  2
#> [ CPUf32{} ]