Qu

round

Builtin index · Core maths

result = floor(x)

Input: x · Output: result

What it is

Standard rounding functions, elementwise: floor toward negative infinity, ceil toward positive infinity, round to the nearest integer (half away from zero). x is a scalar, Vec, or Mat/Signal.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = floor(x)
x scalar, Vec, Mat, or Signalnot documented yet
result —
Returns exactly the same type and shape as x, rounded elementwise.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

Fs = 2000
fc = 60
lp = butter(4, "low", fc, Fs)
H = freqz(lp, 512)
print(H)
mag_db = 20 * log10(abs(H))
i_fc = round(fc / (Fs / 2) * (length(H) - 1))
i_dc = 0
i_nyq = length(H) - 1
print("Gain at DC: {mag_db[i_dc]:.2f} dB")
print("Gain near cutoff ({fc} Hz): {mag_db[i_fc]:.2f} dB (expect close to -3 dB)")
print("Gain at Nyquist: {mag_db[i_nyq]:.2f} dB")

from tour

How it works

round(x) to a whole number; round(x, digits) to that many decimals. Half away from zero, the arithmetic convention, not banker's rounding -- a measurement rounded for a table should match what the reader would do by hand.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.

See also

floor, ceil — documented in the same entry.