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!
===Double rounding=== {{Anchor|Sticky rounding|Rounding to odd}} Rounding a number twice in succession to different levels of precision, with the latter precision being coarser, is not guaranteed to give the same result as rounding once to the final precision except in the case of directed rounding.<ref group="nb" name="NB_Double"/> For instance rounding 9.46 to one decimal gives 9.5, and then 10 when rounding to integer using rounding half to even, but would give 9 when rounded to integer directly. Borman and Chatfield<ref>{{cite journal |last1=Borman |first1=Phil |last2=Chatfield |first2=Marion |title=Avoid the perils of using rounded data |journal=Journal of Pharmaceutical and Biomedical Analysis |date=10 November 2015 |volume=115 |pages=506β507 |doi=10.1016/j.jpba.2015.07.021 |pmid=26299526}}</ref> discuss the implications of double rounding when comparing data rounded to one decimal place to specification limits expressed using integers. In ''Martinez v. Allstate'' and ''Sendejo v. Farmers'', litigated between 1995 and 1997, the insurance companies argued that double rounding premiums was permissible and in fact required. The US courts ruled against the insurance companies and ordered them to adopt rules to ensure single rounding.<ref>{{cite book |title=Class Action Dilemmas: Pursuing Public Goals for Private Gain |url=https://archive.org/details/classactiondilem00debo |url-access=registration |author=Deborah R. Hensler |pages=[https://archive.org/details/classactiondilem00debo/page/255 255β293] |isbn=0-8330-2601-1 |publisher=RAND |date=2000}}</ref> Some computer languages and the [[IEEE 754-2008 revision|IEEE 754-2008]] standard dictate that in straightforward calculations the result should not be rounded twice. This has been a particular problem with Java as it is designed to be run identically on different machines, special programming tricks have had to be used to achieve this with [[x87]] floating point.<ref>{{cite journal |title=When is double rounding innocuous? |author=Samuel A. Figueroa |publisher=ACM |journal=ACM SIGNUM Newsletter |volume=30 |issue=3 |date=July 1995 |pages=21β25 |doi=10.1145/221332.221334 |s2cid=14829295|doi-access=free }}</ref><ref>{{cite web |title=Efficiently producing default orthogonal IEEE double results using extended IEEE hardware |author=Roger Golliver |publisher=Intel |date=October 1998 |url=https://www.open-std.org/JTC1/SC22/JSG/docs/m3/docs/jsgn326.pdf}}</ref> The Java language was changed to allow different results where the difference does not matter and require a [[strictfp]] qualifier to be used when the results have to conform accurately; strict floating point has been restored in Java 17.<ref>{{cite web |first=Joseph D. |last=Darcy |title=JEP 306: Restore Always-Strict Floating-Point Semantics |url=http://openjdk.java.net/jeps/306 |access-date=2021-09-12}}</ref> In some algorithms, an intermediate result is computed in a larger precision, then must be rounded to the final precision. Double rounding can be avoided by choosing an adequate rounding for the intermediate computation. This consists in avoiding to round to midpoints for the final rounding (except when the midpoint is exact). In binary arithmetic, the idea is to round the result toward zero, and set the least significant bit to 1 if the rounded result is inexact; this rounding is called ''sticky rounding''.<ref>{{cite journal |last1=Moore |first1=J. Strother |last2=Lynch |first2=Tom |last3=Kaufmann |first3=Matt |date=1996 |title=A mechanically checked proof of the correctness of the kernel of the AMD5K86 floating-point division algorithm |url=https://www.cs.utexas.edu/users/moore/publications/divide_paper.pdf |journal=IEEE Transactions on Computers |volume=47 |citeseerx=10.1.1.43.3309 |access-date=2016-08-02 |doi=10.1109/12.713311}}</ref> Equivalently, it consists in returning the intermediate result when it is exactly representable, and the nearest floating-point number with an odd significand otherwise; this is why it is also known as ''rounding to odd''.<ref>{{cite journal |url=https://inria.hal.science/inria-00080427v2/document |title=Emulation of a FMA and correctly-rounded sums: proved algorithms using rounding to odd |last1=Boldo |first1=Sylvie |author1-link=Sylvie Boldo |last2=Melquiond |first2=Guillaume |date=2008 |journal=IEEE Transactions on Computers |volume=57 |issue=4 |pages=462β471 |format=PDF |doi=10.1109/TC.2007.70819 |s2cid=1850330 |access-date=2016-08-02}}</ref><ref>{{cite web |url=https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21718#c25 |title=21718 β real.c rounding not perfect |website=gcc.gnu.org}}</ref> A concrete implementation of this approach, for binary and decimal arithmetic, is implemented as [[#Rounding to prepare for shorter precision|Rounding to prepare for shorter precision]].
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