Round
Round (⸠
, ⁅
) (respectively in TinyAPL and Uiua) is a monadic scalar function that rounds a number. While it doesn't appear in most APLs, its behavior is most commonly replicated with the idiom ⌊0.5+y
.
Examples
⸠0.1‿2.9 ⟨0 ⋄ 3⟩
Variants
In traditional mathematics and programming, there are multiple definitions of rounding a number when its fractional part is one half.
The traditional APL expression always rounds halves up, and TinyAPL also chooses this behavior:
⸠0.5‿1.5‿¯0.5‿¯1.5 ⟨1 ⋄ 2 ⋄ 0 ⋄ ¯1⟩
Another way is to round away from zero, which is equivalent to rounding positive numbers above and negative numbers below. This is chosen by Uiua:
⁅0.5_1.5_¯0.5_¯1.5 ## [1 2 ¯1 ¯2]
A third way is rounding to the nearest even integer. This might be preferred because it reduces bias and accumulation of error in subsequent rounding[1]. This is the behavior used by Kap:
math:round 0.5 1.5 ¯0.5 ¯1.5 0 2 0 -2
External links
Documentation
References