|
179 | 179 |
|
180 | 180 | The first and maybe most common one is \pythonilIdx{round}. |
181 | 181 | This function accepts a \pythonilIdx{float} and rounds it to the nearest integer. |
182 | | -If two integer numbers are equally close to it, it returns the one that is even~\cite{PSF:P3D:TPSL:BIF}. |
183 | | -This rounding method is called \emph{\pgls{bankersRounding}}. |
| 182 | +If two integer numbers are equally close to it, it returns the one that is even~\cite{PSF:P3D:TPSL:BIF:R}. |
| 183 | +This rounding method is called \emph{\pgls{bankersRounding}}~\cite{PWZLZZLW2025HIOIBFPRA}. |
184 | 184 | It is defined in the IEEE~754 standard for floating point arithmetics~\cite{IEEE2019ISFFPA} and used in many applications today, including Alipay\textsuperscript{+}~\cite{APDOC:BR}. |
185 | 185 |
|
186 | | -This rounding behavior can be very surprising, as we learned in school that $x.5$ should be rounded to~$x+1$. |
187 | | -Well, I learned it like this in Germany (and \pgls{Java}'s~\pythonil{Math.round} also works like that\cite{O2024JPSEJDKV2AS}), but elsewhere it may be taught differently{\dots} |
| 186 | +This rounding behavior can be very surprising, as we learned in school that numbers of the form~$x.5$ should be rounded to~$x+1$. |
| 187 | +Well, I learned it like this in Germany~(and \pgls{Java}'s~\pythonil{Math.round} also works like that\cite{O2024JPSEJDKV2AS}), but elsewhere it may be taught differently{\dots} |
188 | 188 | Under \pgls{bankersRounding}, this will only happen with \pythonilIdx{round} if $x+1$~is even. |
189 | 189 | The reason why \pgls{bankersRounding} is preferred is that it is not biased in any direction~\cite{MB2005RA1,SE:SO:WDP3RHTE}. |
190 | | -If $x.5$ is always rounded toward~$x+1$ and we have many numbers of the form $x.5$, then the average rounded result tends to be somewhat larger than the average of the unrounded numbers. |
191 | | -\Pgls{bankersRounding} avoids this problem by sometimes rounding numbers ending in~5 to larger and sometimes to smaller values. |
192 | | - |
| 190 | +If $x.5$ is always rounded toward~$x+1$ and we have many numbers of the form~$x.5$, then the average rounded result tends to be somewhat larger than the average of the unrounded numbers. |
| 191 | +\Pgls{bankersRounding} avoids this problem by sometimes rounding numbers ending in~5 to larger and sometimes to smaller values.% |
| 192 | +% |
| 193 | +\begin{sloppypar}% |
193 | 194 | Let's look at the following example. |
194 | 195 | Assume we have a list~$S$ of numbers such that~$S=(0.5, 1.5, 2.5, 3.5, 4.5, 5.5)$. |
195 | 196 | Traditional \inQuotes{school rounding,} which rounds up numbers ending in~.5, would give us~$S_s = (1, 2, 3, 4, 5, 6)$, as all numbers are rounded up since they all end in~0.5. |
|
203 | 204 | This would also hold for the arithmetic means~\arithMean. |
204 | 205 | This, of course, only plays a role if many values ending in~.5 appear. |
205 | 206 | But it is quite clear why bankers would like that. |
206 | | -If you work in a bank and shuffle around large sums of money, you certainly would like these sums to add up properly{\dots} |
207 | | - |
| 207 | +If you work in a bank and shuffle around large sums of money, you certainly would like these sums to add up properly{\dots}% |
| 208 | +\end{sloppypar}% |
| 209 | +% |
208 | 210 | We find examples of the behavior of \pythonilIdx{round} in \cref{exec:float_rounding}. |
209 | 211 | \pythonil{round(0.4)}~yields the integer~\pythonil{0}, as expected. |
210 | 212 | \pythonil{round(0.5)}~returns~\pythonil{0} as well, which one may not expect -- but \pythonil{0}~is even and \pythonil{1}~would be odd. |
|
0 commit comments