Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Rounding
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Rounding to prepare for shorter precision=== This rounding mode is used to avoid getting a potentially wrong result after [[#Double rounding|multiple roundings]]. This can be achieved if all roundings except the final one are done using rounding to prepare for shorter precision ("RPSP"), and only the final rounding uses the externally requested mode. With decimal arithmetic, final digits of 0 and 5 are avoided; if there is a choice between numbers with the least significant digit 0 or 1, 4 or 5, 5 or 6, 9 or 0, then the digit different from 0 or 5 shall be selected; otherwise, the choice is arbitrary. IBM defines that, in the latter case, a digit with the smaller magnitude shall be selected.<ref>[https://www.ibm.com/support/pages/zarchitecture-principles-operation IBM z/Architecture Principles of Operation]</ref> RPSP can be applied with the step between two consequent roundings as small as a single digit (for example, rounding to 1/10 can be applied after rounding to 1/100). For example, when rounding to integer, * 20.0 is rounded to 20; * 20.01, 20.1, 20.9, 20.99, 21, 21.01, 21.9, 21.99 are rounded to 21 (avoiding a final 0); * 22.0, 22.1, 22.9, 22.99 are rounded to 22; * 24.0, 24.1, 24.9, 24.99 are rounded to 24 (avoiding a final 5); * 25.0 is rounded to 25; * 25.01, 25.1 are rounded to 26 (avoiding a final 5). In the example from "[[#Double rounding|Double rounding]]" section, rounding 9.46 to one decimal gives 9.4, which rounding to integer in turn gives 9. With binary arithmetic, this rounding is also called "round to odd" (not to be confused with "[[#Rounding half to odd|round half to odd]]"). For example, when rounding to 1/4 (0.01 in binary), * {{math|1=''x'' = 2.0}} β result is 2 (10.00 in binary) * {{math|2.0 < ''x'' < 2.5}} β result is 2.25 (10.01 in binary) * {{math|1=''x'' = 2.5}} β result is 2.5 (10.10 in binary) * {{math|2.5 < ''x'' < 3.0}} β result is 2.75 (10.11 in binary) * {{math|1=''x'' = 3.0}} β result is 3 (11.00 in binary) For correct results with binary arithmetic, each rounding step must remove at least 2 binary digits, otherwise, wrong results may appear. For example, * 3.125 RPSP to 1/4 β result is 3.25 * 3.25 RPSP to 1/2 β result is 3.5 * 3.5 round-half-to-even to 1 β result is 4 (wrong) If the erroneous middle step is removed, the final rounding to integer rounds 3.25 to the correct value of 3. RPSP is implemented in hardware in IBM [[zSeries]] and [[pSeries]]. In [[Python (programming language)|Python]] module "Decimal", [[Tcl]] module "math", [[Haskell]] package "decimal-arithmetic", and possibly others, this mode is called ROUND_05UP or round05up.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Rounding
(section)
Add topic