round¶
- round(x: array, /) array ¶
Rounds each element
x_i
of the input arrayx
to the nearest integer-valued number.Note
For complex floating-point operands, real and imaginary components must be independently rounded to the nearest integer-valued number.
Rounded real and imaginary components must be equal to their equivalent rounded real-valued floating-point counterparts (i.e., for complex-valued
x
,real(round(x))
must equalround(real(x)))
andimag(round(x))
must equalround(imag(x))
).- Parameters:
x (array) – input array. Should have a numeric data type.
- Returns:
out (array) – an array containing the rounded result for each element in
x
. The returned array must have the same data type asx
.
Notes
Special cases
Note
For complex floating-point operands, the following special cases apply to real and imaginary components independently (e.g., if
real(x_i)
isNaN
, the rounded real component isNaN
).If
x_i
is already integer-valued, the result isx_i
.
For floating-point operands,
If
x_i
is+infinity
, the result is+infinity
.If
x_i
is-infinity
, the result is-infinity
.If
x_i
is+0
, the result is+0
.If
x_i
is-0
, the result is-0
.If
x_i
isNaN
, the result isNaN
.If two integers are equally close to
x_i
, the result is the even integer closest tox_i
.
Changed in version 2022.12: Added complex data type support.