<s>
Rounding	B-Algorithm
means	O
replacing	O
a	O
number	O
with	O
an	O
approximate	O
value	O
that	O
has	O
a	O
shorter	O
,	O
simpler	O
,	O
or	O
more	O
explicit	O
representation	O
.	O
</s>
<s>
Rounding	B-Algorithm
is	O
often	O
done	O
to	O
obtain	O
a	O
value	O
that	O
is	O
easier	O
to	O
report	O
and	O
communicate	O
than	O
the	O
original	O
.	O
</s>
<s>
Rounding	B-Algorithm
can	O
also	O
be	O
important	O
to	O
avoid	O
misleadingly	B-Algorithm
precise	I-Algorithm
reporting	O
of	O
a	O
computed	O
number	O
,	O
measurement	O
,	O
or	O
estimate	O
;	O
for	O
example	O
,	O
a	O
quantity	O
that	O
was	O
computed	O
as	O
but	O
is	O
known	O
to	O
be	O
accurate	O
only	O
to	O
within	O
a	O
few	O
hundred	O
units	O
is	O
usually	O
better	O
stated	O
as	O
"	O
about	O
"	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
rounding	B-Algorithm
of	O
exact	O
numbers	O
will	O
introduce	O
some	O
round-off	B-Algorithm
error	I-Algorithm
in	O
the	O
reported	O
result	O
.	O
</s>
<s>
Rounding	B-Algorithm
is	O
almost	O
unavoidable	O
when	O
reporting	O
many	O
computations	O
–	O
especially	O
when	O
dividing	O
two	O
numbers	O
in	O
integer	O
or	O
fixed-point	O
arithmetic	O
;	O
when	O
computing	O
mathematical	O
functions	O
such	O
as	O
square	O
roots	O
,	O
logarithms	O
,	O
and	O
sines	O
;	O
or	O
when	O
using	O
a	O
floating-point	B-Algorithm
representation	I-Algorithm
with	O
a	O
fixed	O
number	O
of	O
significant	B-Architecture
digits	I-Architecture
.	O
</s>
<s>
In	O
a	O
sequence	O
of	O
calculations	O
,	O
these	O
rounding	B-Algorithm
errors	I-Algorithm
generally	O
accumulate	B-General_Concept
,	O
and	O
in	O
certain	O
ill-conditioned	B-Algorithm
cases	O
they	O
may	O
make	O
the	O
result	O
meaningless	O
.	O
</s>
<s>
Accurate	O
rounding	B-Algorithm
of	O
transcendental	O
mathematical	O
functions	O
is	O
difficult	O
because	O
the	O
number	O
of	O
extra	O
digits	O
that	O
need	O
to	O
be	O
calculated	O
to	O
resolve	O
whether	O
to	O
round	O
up	O
or	O
down	O
cannot	O
be	O
known	O
in	O
advance	O
.	O
</s>
<s>
Rounding	B-Algorithm
has	O
many	O
similarities	O
to	O
the	O
quantization	B-Algorithm
that	O
occurs	O
when	O
physical	O
quantities	O
must	O
be	O
encoded	O
by	O
numbers	O
or	O
digital	O
signals	O
.	O
</s>
<s>
A	O
wavy	O
equals	O
sign	O
( ≈	O
:	O
approximately	O
equal	O
to	O
)	O
is	O
sometimes	O
used	O
to	O
indicate	O
rounding	B-Algorithm
of	O
exact	O
numbers	O
,	O
e.g.	O
,	O
9.98	O
≈	O
10	O
.	O
</s>
<s>
Ideal	O
characteristics	O
of	O
rounding	B-Algorithm
methods	O
include	O
:	O
</s>
<s>
Rounding	B-Algorithm
should	O
be	O
done	O
by	O
a	O
function	O
.	O
</s>
<s>
Calculations	O
done	O
with	O
rounding	B-Algorithm
should	O
be	O
close	O
to	O
those	O
done	O
without	O
rounding	B-Algorithm
.	O
</s>
<s>
As	O
a	O
result	O
of	O
(	O
1	O
)	O
and	O
(	O
2	O
)	O
,	O
the	O
output	O
from	O
rounding	B-Algorithm
should	O
be	O
close	O
to	O
its	O
input	O
,	O
often	O
as	O
close	O
as	O
possible	O
by	O
some	O
metric	O
.	O
</s>
<s>
To	O
be	O
considered	O
rounding	B-Algorithm
,	O
the	O
range	B-Algorithm
will	O
be	O
a	O
subset	O
of	O
the	O
domain	B-Algorithm
,	O
in	O
general	O
discrete	O
.	O
</s>
<s>
A	O
classical	O
range	B-Algorithm
is	O
the	O
integers	O
,	O
Z	O
.	O
</s>
<s>
Rounding	B-Algorithm
should	O
preserve	O
symmetries	O
that	O
already	O
exist	O
between	O
the	O
domain	B-Algorithm
and	O
range	B-Algorithm
.	O
</s>
<s>
With	O
finite	O
precision	B-Architecture
(	O
or	O
a	O
discrete	O
domain	B-Algorithm
)	O
,	O
this	O
translates	O
to	O
removing	O
bias	O
.	O
</s>
<s>
A	O
rounding	B-Algorithm
method	O
should	O
have	O
utility	O
in	O
computer	O
science	O
or	O
human	O
arithmetic	O
where	O
finite	O
precision	B-Architecture
is	O
used	O
,	O
and	O
speed	O
is	O
a	O
consideration	O
.	O
</s>
<s>
Because	O
it	O
is	O
not	O
usually	O
possible	O
for	O
a	O
method	O
to	O
satisfy	O
all	O
ideal	O
characteristics	O
,	O
many	O
different	O
rounding	B-Algorithm
methods	O
exist	O
.	O
</s>
<s>
As	O
a	O
general	O
rule	O
,	O
rounding	B-Algorithm
is	O
idempotent	O
;	O
i.e.	O
,	O
once	O
a	O
number	O
has	O
been	O
rounded	O
,	O
rounding	B-Algorithm
it	O
again	O
will	O
not	O
change	O
its	O
value	O
.	O
</s>
<s>
Rounding	B-Algorithm
functions	I-Algorithm
are	O
also	O
monotonic	O
;	O
i.e.	O
,	O
.	O
</s>
<s>
In	O
the	O
general	O
case	O
of	O
a	O
discrete	O
range	B-Algorithm
,	O
they	O
are	O
piecewise	O
constant	O
functions	O
.	O
</s>
<s>
Typical	O
rounding	B-Algorithm
problems	O
include	O
:	O
</s>
<s>
Rounding	B-Algorithm
problemExample	O
inputResultRounding	O
criterionApproximating	O
an	O
irrational	O
number	O
by	O
a	O
fraction	O
22	O
/	O
71-digit-denominatorApproximating	O
a	O
rational	O
number	O
by	O
another	O
fraction	O
with	O
smaller	O
numerator	O
and	O
denominator	O
399	O
/	O
941	O
3	O
/	O
7	O
1-digit-denominatorApproximating	O
a	O
fraction	O
,	O
which	O
have	O
periodic	O
decimal	B-Application
expansion	O
,	O
by	O
a	O
finite	O
decimal	B-Application
fraction5	O
/	O
34	O
decimal	B-Application
placesApproximating	O
a	O
fractional	O
decimal	B-Application
number	O
by	O
one	O
with	O
fewer	O
digits2.182	O
decimal	B-Application
placesApproximating	O
a	O
decimal	B-Application
integer	O
by	O
an	O
integer	O
with	O
more	O
trailing	O
zeros3	O
significant	O
figuresApproximating	O
a	O
large	O
decimal	B-Application
integer	O
using	O
scientific	O
notation	O
×	O
83	O
significant	O
figuresApproximating	O
a	O
value	O
by	O
a	O
multiple	O
of	O
a	O
specified	O
amount48.245Multiple	O
of	O
15Rounding	O
each	O
one	O
of	O
a	O
finite	O
set	O
of	O
real	O
numbers	O
(	O
mostly	O
fractions	O
)	O
to	O
an	O
integer	O
(	O
sometimes	O
the	O
second-nearest	O
integer	O
)	O
so	O
that	O
the	O
sum	O
of	O
the	O
rounded	B-Algorithm
numbers	I-Algorithm
equals	O
the	O
rounded	O
sum	O
of	O
the	O
numbers	O
(	O
needed	O
e.g.	O
</s>
<s>
The	O
most	O
basic	O
form	O
of	O
rounding	B-Algorithm
is	O
to	O
replace	O
an	O
arbitrary	O
number	O
by	O
an	O
integer	O
.	O
</s>
<s>
All	O
the	O
following	O
rounding	B-Algorithm
modes	O
are	O
concrete	O
implementations	O
of	O
an	O
abstract	O
single-argument	O
"	O
round( )	O
"	O
procedure	O
.	O
</s>
<s>
These	O
four	O
methods	O
are	O
called	O
directed	B-Algorithm
rounding	I-Algorithm
,	O
as	O
the	O
displacements	O
from	O
the	O
original	O
number	O
to	O
the	O
rounded	O
value	O
are	O
all	O
directed	O
toward	O
or	O
away	O
from	O
the	O
same	O
limiting	O
value	O
(	O
0	O
,	O
+∞	O
,	O
or	O
−∞	O
)	O
.	O
</s>
<s>
Directed	B-Algorithm
rounding	I-Algorithm
is	O
used	O
in	O
interval	B-Algorithm
arithmetic	I-Algorithm
and	O
is	O
often	O
required	O
in	O
financial	O
calculations	O
.	O
</s>
<s>
Where	O
many	O
calculations	O
are	O
done	O
in	O
sequence	O
,	O
the	O
choice	O
of	O
rounding	B-Algorithm
method	O
can	O
have	O
a	O
very	O
significant	O
effect	O
on	O
the	O
result	O
.	O
</s>
<s>
It	O
was	O
initially	O
set	O
at	O
1000.000	O
(	O
three	O
decimal	B-Architecture
places	I-Architecture
of	O
accuracy	O
)	O
,	O
and	O
after	O
22	O
months	O
had	O
fallen	O
to	O
about	O
520	O
—	O
whereas	O
stock	O
prices	O
had	O
generally	O
increased	O
in	O
the	O
period	O
.	O
</s>
<s>
The	O
problem	O
was	O
caused	O
by	O
the	O
index	O
being	O
recalculated	O
thousands	O
of	O
times	O
daily	O
,	O
and	O
always	O
being	O
rounded	O
down	O
to	O
3	O
decimal	B-Architecture
places	I-Architecture
,	O
in	O
such	O
a	O
way	O
that	O
the	O
rounding	B-Algorithm
errors	I-Algorithm
accumulated	O
.	O
</s>
<s>
Recalculating	O
with	O
better	O
rounding	B-Algorithm
gave	O
an	O
index	O
value	O
of	O
1098.892	O
at	O
the	O
end	O
of	O
the	O
same	O
period	O
.	O
</s>
<s>
round	O
toward	O
zero	O
(	O
or	O
truncate	B-Algorithm
,	O
or	O
round	O
away	O
from	O
infinity	O
)	O
:	O
is	O
the	O
integer	O
that	O
is	O
closest	O
to	O
such	O
that	O
it	O
is	O
between	O
0	O
and	O
(	O
included	O
)	O
;	O
i.e.	O
</s>
<s>
Rounding	B-Algorithm
a	O
number	O
to	O
the	O
nearest	B-Algorithm
integer	I-Algorithm
requires	O
some	O
tie-breaking	O
rule	O
for	O
those	O
cases	O
when	O
is	O
exactly	O
half-way	O
between	O
two	O
integers	O
—	O
that	O
is	O
,	O
when	O
the	O
fraction	O
part	O
of	O
is	O
exactly	O
0.5	O
.	O
</s>
<s>
If	O
it	O
were	O
not	O
for	O
the	O
0.5	O
fractional	O
parts	O
,	O
the	O
round-off	B-Algorithm
errors	I-Algorithm
introduced	O
by	O
the	O
round	O
to	O
nearest	O
method	O
would	O
be	O
symmetric	O
:	O
for	O
every	O
fraction	O
that	O
gets	O
rounded	O
down	O
(	O
such	O
as	O
0.268	O
)	O
,	O
there	O
is	O
a	O
complementary	O
fraction	O
(	O
namely	O
,	O
0.732	O
)	O
that	O
gets	O
rounded	O
up	O
by	O
the	O
same	O
amount	O
.	O
</s>
<s>
When	O
rounding	B-Algorithm
a	O
large	O
set	O
of	O
fixed-point	O
numbers	O
with	O
uniformly	O
distributed	O
fractional	O
parts	O
,	O
the	O
rounding	B-Algorithm
errors	I-Algorithm
by	O
all	O
values	O
,	O
with	O
the	O
omission	O
of	O
those	O
having	O
0.5	O
fractional	O
part	O
,	O
would	O
statistically	O
compensate	O
each	O
other	O
.	O
</s>
<s>
This	O
means	O
that	O
the	O
expected	O
(	O
average	O
)	O
value	O
of	O
the	O
rounded	B-Algorithm
numbers	I-Algorithm
is	O
equal	O
to	O
the	O
expected	O
value	O
of	O
the	O
original	O
numbers	O
when	O
numbers	O
with	O
fractional	O
part	O
0.5	O
from	O
the	O
set	O
are	O
removed	O
.	O
</s>
<s>
In	O
practice	O
,	O
floating-point	B-Algorithm
numbers	I-Algorithm
are	O
typically	O
used	O
,	O
which	O
have	O
even	O
more	O
computational	O
nuances	O
because	O
they	O
are	O
not	O
equally	O
spaced	O
.	O
</s>
<s>
This	O
method	O
only	O
requires	O
checking	O
one	O
digit	O
to	O
determine	O
rounding	B-Algorithm
direction	O
in	O
two	B-General_Concept
's	I-General_Concept
complement	I-General_Concept
and	O
similar	O
representations	O
.	O
</s>
<s>
This	O
is	O
one	O
method	O
used	O
when	O
rounding	B-Algorithm
to	O
significant	B-Architecture
figures	I-Architecture
due	O
to	O
its	O
simplicity	O
.	O
</s>
<s>
This	O
method	O
,	O
also	O
known	O
as	O
commercial	O
rounding	B-Algorithm
,	O
treats	O
positive	O
and	O
negative	O
values	O
symmetrically	O
,	O
and	O
therefore	O
is	O
free	O
of	O
overall	O
positive/negative	O
bias	O
if	O
the	O
original	O
numbers	O
are	O
positive	O
or	O
negative	O
with	O
equal	O
probability	O
.	O
</s>
<s>
It	O
is	O
often	O
used	O
for	O
currency	O
conversions	O
and	O
price	O
roundings	B-Algorithm
(	O
when	O
the	O
amount	O
is	O
first	O
converted	O
into	O
the	O
smallest	O
significant	O
subdivision	O
of	O
the	O
currency	O
,	O
such	O
as	O
cents	O
of	O
a	O
euro	O
)	O
as	O
it	O
is	O
easy	O
to	O
explain	O
by	O
just	O
considering	O
the	O
first	O
fractional	O
digit	O
,	O
independently	O
of	O
supplementary	O
precision	B-Architecture
digits	O
or	O
sign	O
of	O
the	O
amount	O
(	O
for	O
strict	O
equivalence	O
between	O
the	O
paying	O
and	O
recipient	O
of	O
the	O
amount	O
)	O
.	O
</s>
<s>
This	O
variant	O
of	O
the	O
round-to-nearest	O
method	O
is	O
also	O
called	O
convergent	O
rounding	B-Algorithm
,	O
statistician	B-Algorithm
's	I-Algorithm
rounding	I-Algorithm
,	O
Dutch	O
rounding	B-Algorithm
,	O
Gaussian	O
rounding	B-Algorithm
,	O
odd	O
–	O
even	O
rounding	B-Algorithm
,	O
or	O
bankers	O
 '	O
rounding	B-Algorithm
.	O
</s>
<s>
This	O
is	O
the	O
default	O
rounding	B-Algorithm
mode	O
used	O
in	O
IEEE	O
754	O
operations	O
for	O
results	O
in	O
binary	B-Algorithm
floating-point	I-Algorithm
formats	O
,	O
and	O
used	O
when	O
rounding	B-Algorithm
to	O
significant	B-Architecture
figures	I-Architecture
.	O
</s>
<s>
This	O
variant	O
is	O
almost	O
never	O
used	O
in	O
computations	O
,	O
except	O
in	O
situations	O
where	O
one	O
wants	O
to	O
avoid	O
increasing	O
the	O
scale	O
of	O
floating-point	B-Algorithm
numbers	I-Algorithm
,	O
which	O
have	O
a	O
limited	O
exponent	O
range	B-Algorithm
.	O
</s>
<s>
Effectively	O
,	O
this	O
mode	O
prefers	O
preserving	O
the	O
existing	O
scale	O
of	O
tie	O
numbers	O
,	O
avoiding	O
out-of-range	O
results	O
when	O
possible	O
for	O
numeral	O
systems	O
of	O
even	O
radix	O
(	O
such	O
as	O
binary	O
and	O
decimal	B-Application
)	O
.	O
</s>
<s>
This	O
rounding	B-Algorithm
mode	O
(	O
RPSP	O
in	O
this	O
chapter	O
)	O
is	O
used	O
to	O
avoid	O
getting	O
wrong	O
result	O
with	O
double	O
(	O
including	O
multiple	O
)	O
rounding	B-Algorithm
.	O
</s>
<s>
With	O
this	O
rounding	B-Algorithm
mode	O
,	O
one	O
can	O
avoid	O
wrong	O
result	O
after	O
double	O
rounding	B-Algorithm
,	O
if	O
all	O
roundings	B-Algorithm
except	O
the	O
final	O
one	O
are	O
done	O
using	O
RPSP	O
,	O
and	O
only	O
final	O
rounding	B-Algorithm
uses	O
the	O
externally	O
requested	O
mode	O
.	O
</s>
<s>
With	O
decimal	B-Application
arithmetic	O
,	O
if	O
there	O
is	O
a	O
choice	O
between	O
numbers	O
with	O
the	O
smallest	O
significant	B-Architecture
digit	I-Architecture
0	O
or	O
1	O
,	O
4	O
or	O
5	O
,	O
5	O
or	O
6	O
,	O
9	O
or	O
0	O
,	O
then	O
the	O
digit	O
different	O
from	O
0	O
or	O
5	O
shall	O
be	O
selected	O
;	O
otherwise	O
,	O
choice	O
is	O
arbitrary	O
.	O
</s>
<s>
RPSP	O
can	O
be	O
applied	O
with	O
the	O
step	O
between	O
two	O
consequent	O
roundings	B-Algorithm
as	O
small	O
as	O
a	O
single	O
digit	O
(	O
for	O
example	O
,	O
rounding	B-Algorithm
to	O
1/10	O
can	O
be	O
applied	O
after	O
rounding	B-Algorithm
to	O
1/100	O
)	O
.	O
</s>
<s>
For	O
example	O
,	O
when	O
rounding	B-Algorithm
to	O
integer	O
,	O
</s>
<s>
In	O
the	O
example	O
from	O
"	O
Double	O
rounding	B-Algorithm
"	O
section	O
,	O
rounding	B-Algorithm
9.46	O
to	O
one	O
decimal	B-Application
gives	O
9.4	O
,	O
which	O
rounding	B-Algorithm
to	O
integer	O
in	O
turn	O
gives	O
9	O
.	O
</s>
<s>
With	O
binary	O
arithmetic	O
,	O
the	O
rounding	B-Algorithm
is	O
made	O
as	O
"	O
round	O
to	O
odd	O
"	O
(	O
not	O
to	O
be	O
mixed	O
with	O
"	O
round	O
half	O
to	O
odd	O
"	O
.	O
)	O
</s>
<s>
For	O
example	O
,	O
when	O
rounding	B-Algorithm
to	O
1/4	O
:	O
</s>
<s>
One	O
method	O
,	O
more	O
obscure	O
than	O
most	O
,	O
is	O
to	O
alternate	O
direction	O
when	O
rounding	B-Algorithm
a	O
number	O
with	O
0.5	O
fractional	O
part	O
.	O
</s>
<s>
Whenever	O
the	O
fractional	O
part	O
is	O
0.5	O
,	O
alternate	O
rounding	B-Algorithm
up	O
or	O
down	O
:	O
for	O
the	O
first	O
occurrence	O
of	O
a	O
0.5	O
fractional	O
part	O
,	O
round	O
up	O
,	O
for	O
the	O
second	O
occurrence	O
,	O
round	O
down	O
,	O
and	O
so	O
on	O
.	O
</s>
<s>
Alternatively	O
,	O
the	O
first	O
0.5	O
fractional	O
part	O
rounding	B-Algorithm
can	O
be	O
determined	O
by	O
a	O
random	B-Algorithm
seed	I-Algorithm
.	O
</s>
<s>
"	O
Up	O
"	O
and	O
"	O
down	O
"	O
can	O
be	O
any	O
two	O
rounding	B-Algorithm
methods	O
that	O
oppose	O
each	O
other	O
-	O
toward	O
and	O
away	O
from	O
positive	O
infinity	O
or	O
toward	O
and	O
away	O
from	O
zero	O
.	O
</s>
<s>
An	O
advantage	O
over	O
alternate	O
tie-breaking	O
is	O
that	O
the	O
last	O
direction	O
of	O
rounding	B-Algorithm
on	O
the	O
0.5	O
fractional	O
part	O
does	O
not	O
have	O
to	O
be	O
"	O
remembered	O
"	O
.	O
</s>
<s>
Rounding	B-Algorithm
as	O
follows	O
to	O
one	O
of	O
the	O
closest	O
integer	O
toward	O
negative	O
infinity	O
and	O
the	O
closest	O
integer	O
toward	O
positive	O
infinity	O
,	O
with	O
a	O
probability	O
dependent	O
on	O
the	O
proximity	O
is	O
called	O
stochastic	B-Algorithm
rounding	I-Algorithm
and	O
will	O
give	O
an	O
unbiased	O
result	O
on	O
average	O
.	O
</s>
<s>
Stochastic	B-Algorithm
rounding	I-Algorithm
can	O
be	O
accurate	O
in	O
a	O
way	O
that	O
a	O
rounding	B-Algorithm
function	I-Algorithm
can	O
never	O
be	O
.	O
</s>
<s>
For	O
example	O
,	O
suppose	O
one	O
started	O
with	O
0	O
and	O
added	O
0.3	O
to	O
that	O
one	O
hundred	O
times	O
while	O
rounding	B-Algorithm
the	O
running	O
total	O
between	O
every	O
addition	O
.	O
</s>
<s>
The	O
result	O
would	O
be	O
0	O
with	O
regular	O
rounding	B-Algorithm
,	O
but	O
with	O
stochastic	B-Algorithm
rounding	I-Algorithm
,	O
the	O
expected	O
result	O
would	O
be	O
30	O
,	O
which	O
is	O
the	O
same	O
value	O
obtained	O
without	O
rounding	B-Algorithm
.	O
</s>
<s>
This	O
can	O
be	O
useful	O
in	O
machine	O
learning	O
where	O
the	O
training	O
may	O
use	O
low	O
precision	B-Architecture
arithmetic	O
iteratively	O
.	O
</s>
<s>
Stochastic	B-Algorithm
rounding	I-Algorithm
is	O
also	O
a	O
way	O
to	O
achieve	O
1-dimensional	O
dithering	O
.	O
</s>
<s>
The	O
most	O
common	O
type	O
of	O
rounding	B-Algorithm
is	O
to	O
round	O
to	O
an	O
integer	O
;	O
or	O
,	O
more	O
generally	O
,	O
to	O
an	O
integer	O
multiple	O
of	O
some	O
increment	O
—	O
such	O
as	O
rounding	B-Algorithm
to	O
whole	O
tenths	O
of	O
seconds	O
,	O
hundredths	O
of	O
a	O
dollar	O
,	O
to	O
whole	O
multiples	O
of	O
1/2	O
or	O
1/8	O
inch	O
,	O
to	O
whole	O
dozens	O
or	O
thousands	O
,	O
etc	O
.	O
</s>
<s>
In	O
general	O
,	O
rounding	B-Algorithm
a	O
number	O
to	O
a	O
multiple	O
of	O
some	O
specified	O
positive	O
value	O
entails	O
the	O
following	O
steps	O
:	O
</s>
<s>
For	O
example	O
,	O
rounding	B-Algorithm
=	O
2.1784	O
dollars	O
to	O
whole	O
cents	O
(	O
i.e.	O
,	O
to	O
a	O
multiple	O
of	O
0.01	O
)	O
entails	O
computing	O
2.1784	O
/	O
0.01	O
=	O
217.84	O
,	O
then	O
rounding	B-Algorithm
that	O
to	O
218	O
,	O
and	O
finally	O
computing	O
218	O
×	O
0.01	O
=	O
2.18	O
.	O
</s>
<s>
When	O
rounding	B-Algorithm
to	O
a	O
predetermined	O
number	O
of	O
significant	B-Architecture
digits	I-Architecture
,	O
the	O
increment	O
depends	O
on	O
the	O
magnitude	O
of	O
the	O
number	O
to	O
be	O
rounded	O
(	O
or	O
of	O
the	O
rounded	O
result	O
)	O
.	O
</s>
<s>
For	O
display	O
to	O
humans	O
,	O
that	O
usually	O
means	O
the	O
decimal	B-Application
numeral	I-Application
system	I-Application
(	O
that	O
is	O
,	O
is	O
an	O
integer	O
times	O
a	O
power	O
of	O
10	O
,	O
like	O
1/1000	O
or	O
25/100	O
)	O
.	O
</s>
<s>
The	O
abstract	O
single-argument	O
"	O
round( )	O
"	O
function	O
that	O
returns	O
an	O
integer	O
from	O
an	O
arbitrary	O
real	O
value	O
has	O
at	O
least	O
a	O
dozen	O
distinct	O
concrete	O
definitions	O
presented	O
in	O
the	O
rounding	B-Algorithm
to	O
integer	O
section	O
.	O
</s>
<s>
Rounding	B-Algorithm
to	O
a	O
specified	O
power	O
is	O
very	O
different	O
from	O
rounding	B-Algorithm
to	O
a	O
specified	O
multiple	O
;	O
for	O
example	O
,	O
it	O
is	O
common	O
in	O
computing	O
to	O
need	O
to	O
round	O
a	O
number	O
to	O
a	O
whole	O
power	O
of	O
2	O
.	O
</s>
<s>
Many	O
of	O
the	O
caveats	O
applicable	O
to	O
rounding	B-Algorithm
to	O
a	O
multiple	O
are	O
applicable	O
to	O
rounding	B-Algorithm
to	O
a	O
power	O
.	O
</s>
<s>
This	O
type	O
of	O
rounding	B-Algorithm
,	O
which	O
is	O
also	O
named	O
rounding	B-Algorithm
to	O
a	O
logarithmic	O
scale	O
,	O
is	O
a	O
variant	O
of	O
rounding	B-Algorithm
to	O
a	O
specified	O
power	O
.	O
</s>
<s>
Rounding	B-Algorithm
on	O
a	O
logarithmic	O
scale	O
is	O
accomplished	O
by	O
taking	O
the	O
log	O
of	O
the	O
amount	O
and	O
doing	O
normal	O
rounding	B-Algorithm
to	O
the	O
nearest	O
value	O
on	O
the	O
log	O
scale	O
.	O
</s>
<s>
In	O
floating-point	B-Algorithm
arithmetic	I-Algorithm
,	O
rounding	B-Algorithm
aims	O
to	O
turn	O
a	O
given	O
value	O
into	O
a	O
value	O
with	O
a	O
specified	O
number	O
of	O
digits	O
.	O
</s>
<s>
The	O
number	O
is	O
a	O
power	O
of	O
the	O
base	O
(	O
usually	O
2	O
or	O
10	O
)	O
of	O
the	O
floating-point	B-Algorithm
representation	I-Algorithm
.	O
</s>
<s>
Apart	O
from	O
this	O
detail	O
,	O
all	O
the	O
variants	O
of	O
rounding	B-Algorithm
discussed	O
above	O
apply	O
to	O
the	O
rounding	B-Algorithm
of	O
floating-point	B-Algorithm
numbers	I-Algorithm
as	O
well	O
.	O
</s>
<s>
The	O
algorithm	O
for	O
such	O
rounding	B-Algorithm
is	O
presented	O
in	O
the	O
Scaled	O
rounding	B-Algorithm
section	O
above	O
,	O
but	O
with	O
a	O
constant	O
scaling	O
factor	O
=	O
1	O
,	O
and	O
an	O
integer	O
base	O
>1	O
.	O
</s>
<s>
Where	O
the	O
rounded	O
result	O
would	O
overflow	O
the	O
result	O
for	O
a	O
directed	B-Algorithm
rounding	I-Algorithm
is	O
either	O
the	O
appropriate	O
signed	O
infinity	O
when	O
"	O
rounding	B-Algorithm
away	O
from	O
zero	O
"	O
,	O
or	O
the	O
highest	O
representable	O
positive	O
finite	O
number	O
(	O
or	O
the	O
lowest	O
representable	O
negative	O
finite	O
number	O
if	O
is	O
negative	O
)	O
,	O
when	O
"	O
rounding	B-Algorithm
toward	O
zero	O
"	O
.	O
</s>
<s>
This	O
problem	O
is	O
fairly	O
distinct	O
from	O
that	O
of	O
rounding	B-Algorithm
a	O
value	O
to	O
a	O
fixed	O
number	O
of	O
decimal	B-Application
or	O
binary	O
digits	O
,	O
or	O
to	O
a	O
multiple	O
of	O
a	O
given	O
unit	O
.	O
</s>
<s>
This	O
problem	O
is	O
related	O
to	O
Farey	O
sequences	O
,	O
the	O
Stern	B-Data_Structure
–	I-Data_Structure
Brocot	I-Data_Structure
tree	I-Data_Structure
,	O
and	O
continued	O
fractions	O
.	O
</s>
<s>
When	O
a	O
set	O
of	O
preferred	O
values	O
is	O
equally	O
spaced	O
on	O
a	O
logarithmic	O
scale	O
,	O
choosing	O
the	O
closest	O
preferred	O
value	O
to	O
any	O
given	O
value	O
can	O
be	O
seen	O
as	O
a	O
form	O
of	O
scaled	O
rounding	B-Algorithm
.	O
</s>
<s>
In	O
these	O
circumstances	O
,	O
dithering	O
,	O
and	O
a	O
related	O
technique	O
,	O
error	B-Algorithm
diffusion	I-Algorithm
,	O
are	O
normally	O
used	O
.	O
</s>
<s>
A	O
related	O
technique	O
called	O
pulse-width	B-Algorithm
modulation	I-Algorithm
is	O
used	O
to	O
achieve	O
analog	O
type	O
output	O
from	O
an	O
inertial	O
device	O
by	O
rapidly	O
pulsing	O
the	O
power	O
with	O
a	O
variable	O
duty	O
cycle	O
.	O
</s>
<s>
Error	B-Algorithm
diffusion	I-Algorithm
tries	O
to	O
ensure	O
the	O
error	O
,	O
on	O
average	O
,	O
is	O
minimized	O
.	O
</s>
<s>
Floyd	B-Algorithm
–	I-Algorithm
Steinberg	I-Algorithm
dithering	I-Algorithm
is	O
a	O
popular	O
error	B-Algorithm
diffusion	I-Algorithm
procedure	O
when	O
digitizing	O
images	O
.	O
</s>
<s>
Monte	O
Carlo	O
arithmetic	O
is	O
a	O
technique	O
in	O
Monte	B-Algorithm
Carlo	I-Algorithm
methods	I-Algorithm
where	O
the	O
rounding	B-Algorithm
is	O
randomly	O
up	O
or	O
down	O
.	O
</s>
<s>
Stochastic	B-Algorithm
rounding	I-Algorithm
can	O
be	O
used	O
for	O
Monte	O
Carlo	O
arithmetic	O
,	O
but	O
in	O
general	O
,	O
just	O
rounding	B-Algorithm
up	O
or	O
down	O
with	O
equal	O
probability	O
is	O
more	O
often	O
used	O
.	O
</s>
<s>
It	O
is	O
possible	O
to	O
use	O
rounded	O
arithmetic	O
to	O
evaluate	O
the	O
exact	O
value	O
of	O
a	O
function	O
with	O
integer	O
domain	B-Algorithm
and	O
range	B-Algorithm
.	O
</s>
<s>
For	O
example	O
,	O
if	O
an	O
integer	O
is	O
known	O
to	O
be	O
a	O
perfect	O
square	O
,	O
its	O
square	O
root	O
can	O
be	O
computed	O
by	O
converting	O
to	O
a	O
floating-point	B-Algorithm
value	O
,	O
computing	O
the	O
approximate	O
square	O
root	O
of	O
with	O
floating	B-Algorithm
point	I-Algorithm
,	O
and	O
then	O
rounding	B-Algorithm
to	O
the	O
nearest	B-Algorithm
integer	I-Algorithm
.	O
</s>
<s>
If	O
is	O
not	O
too	O
big	O
,	O
the	O
floating-point	B-Algorithm
round-off	B-Algorithm
error	I-Algorithm
in	O
will	O
be	O
less	O
than	O
0.5	O
,	O
so	O
the	O
rounded	O
value	O
will	O
be	O
the	O
exact	O
square	O
root	O
of	O
.	O
</s>
<s>
Rounding	B-Algorithm
a	O
number	O
twice	O
in	O
succession	O
to	O
different	O
levels	O
of	O
precision	B-Architecture
,	O
with	O
the	O
latter	O
precision	B-Architecture
being	O
coarser	O
,	O
is	O
not	O
guaranteed	O
to	O
give	O
the	O
same	O
result	O
as	O
rounding	B-Algorithm
once	O
to	O
the	O
final	O
precision	B-Architecture
except	O
in	O
the	O
case	O
of	O
directed	B-Algorithm
rounding	I-Algorithm
.	O
</s>
<s>
For	O
instance	O
rounding	B-Algorithm
9.46	O
to	O
one	O
decimal	B-Application
gives	O
9.5	O
,	O
and	O
then	O
10	O
when	O
rounding	B-Algorithm
to	O
integer	O
using	O
rounding	B-Algorithm
half	O
to	O
even	O
,	O
but	O
would	O
give	O
9	O
when	O
rounded	O
to	O
integer	O
directly	O
.	O
</s>
<s>
Borman	O
and	O
Chatfield	O
discuss	O
the	O
implications	O
of	O
double	O
rounding	B-Algorithm
when	O
comparing	O
data	O
rounded	O
to	O
one	O
decimal	B-Architecture
place	I-Architecture
to	O
specification	O
limits	O
expressed	O
using	O
integers	O
.	O
</s>
<s>
In	O
Martinez	O
v	O
.	O
Allstate	O
and	O
Sendejo	O
v	O
.	O
Farmers	O
,	O
litigated	O
between	O
1995	O
and	O
1997	O
,	O
the	O
insurance	O
companies	O
argued	O
that	O
double	O
rounding	B-Algorithm
premiums	O
was	O
permissible	O
and	O
in	O
fact	O
required	O
.	O
</s>
<s>
The	O
US	O
courts	O
ruled	O
against	O
the	O
insurance	O
companies	O
and	O
ordered	O
them	O
to	O
adopt	O
rules	O
to	O
ensure	O
single	O
rounding	B-Algorithm
.	O
</s>
<s>
This	O
has	O
been	O
a	O
particular	O
problem	O
with	O
Java	O
as	O
it	O
is	O
designed	O
to	O
be	O
run	O
identically	O
on	O
different	O
machines	O
,	O
special	O
programming	O
tricks	O
have	O
had	O
to	O
be	O
used	O
to	O
achieve	O
this	O
with	O
x87	B-Application
floating	B-Algorithm
point	I-Algorithm
.	O
</s>
<s>
The	O
Java	O
language	O
was	O
changed	O
to	O
allow	O
different	O
results	O
where	O
the	O
difference	O
does	O
not	O
matter	O
and	O
require	O
a	O
strictfp	B-Language
qualifier	O
to	O
be	O
used	O
when	O
the	O
results	O
have	O
to	O
conform	O
accurately	O
;	O
strict	O
floating	B-Algorithm
point	I-Algorithm
has	O
been	O
restored	O
in	O
Java17	O
.	O
</s>
<s>
In	O
some	O
algorithms	O
,	O
an	O
intermediate	O
result	O
is	O
computed	O
in	O
a	O
larger	O
precision	B-Architecture
,	O
then	O
must	O
be	O
rounded	O
to	O
the	O
final	O
precision	B-Architecture
.	O
</s>
<s>
Double	O
rounding	B-Algorithm
can	O
be	O
avoided	O
by	O
choosing	O
an	O
adequate	O
rounding	B-Algorithm
for	O
the	O
intermediate	O
computation	O
.	O
</s>
<s>
This	O
consists	O
in	O
avoiding	O
to	O
round	O
to	O
midpoints	O
for	O
the	O
final	O
rounding	B-Algorithm
(	O
except	O
when	O
the	O
midpoint	O
is	O
exact	O
)	O
.	O
</s>
<s>
In	O
binary	O
arithmetic	O
,	O
the	O
idea	O
is	O
to	O
round	O
the	O
result	O
toward	O
zero	O
,	O
and	O
set	O
the	O
least	O
significant	O
bit	O
to	O
1	O
if	O
the	O
rounded	O
result	O
is	O
inexact	O
;	O
this	O
rounding	B-Algorithm
is	O
called	O
sticky	O
rounding	B-Algorithm
.	O
</s>
<s>
Equivalently	O
,	O
it	O
consists	O
in	O
returning	O
the	O
intermediate	O
result	O
when	O
it	O
is	O
exactly	O
representable	O
,	O
and	O
the	O
nearest	O
floating-point	B-Algorithm
number	I-Algorithm
with	O
an	O
odd	O
significand	O
otherwise	O
;	O
this	O
is	O
why	O
it	O
is	O
also	O
known	O
as	O
rounding	B-Algorithm
to	O
odd	O
.	O
</s>
<s>
A	O
concrete	O
implementation	O
of	O
this	O
approach	O
,	O
for	O
binary	O
and	O
decimal	B-Application
arithmetic	O
,	O
is	O
implemented	O
as	O
Rounding	B-Algorithm
to	O
prepare	O
for	O
shorter	O
precision	B-Architecture
.	O
</s>
<s>
William	O
M	O
.	O
Kahan	O
coined	O
the	O
term	O
"	O
The	O
Table-Maker	O
'	O
s	O
Dilemma	O
"	O
for	O
the	O
unknown	O
cost	O
of	O
rounding	B-Algorithm
transcendental	O
functions	O
:	O
</s>
<s>
The	O
IEEE	O
754	O
floating-point	B-Algorithm
standard	O
guarantees	O
that	O
add	O
,	O
subtract	O
,	O
multiply	O
,	O
divide	O
,	O
fused	O
multiply	O
–	O
add	O
,	O
square	O
root	O
,	O
and	O
floating-point	B-Algorithm
remainder	O
will	O
give	O
the	O
correctly	O
rounded	O
result	O
of	O
the	O
infinite-precision	O
operation	O
.	O
</s>
<s>
However	O
,	O
the	O
2008	O
standard	O
guarantees	O
that	O
conforming	O
implementations	O
will	O
give	O
correctly	O
rounded	O
results	O
which	O
respect	O
the	O
active	O
rounding	B-Algorithm
mode	O
;	O
implementation	O
of	O
the	O
functions	O
,	O
however	O
,	O
is	O
optional	O
.	O
</s>
<s>
However	O
,	O
for	O
an	O
implementation	O
of	O
such	O
a	O
function	O
,	O
determining	O
a	O
limit	O
for	O
a	O
given	O
precision	B-Architecture
on	O
how	O
accurate	O
results	O
need	O
to	O
be	O
computed	O
,	O
before	O
a	O
correctly	O
rounded	O
result	O
can	O
be	O
guaranteed	O
,	O
may	O
demand	O
a	O
lot	O
of	O
computation	O
time	O
or	O
may	O
be	O
out	O
of	O
reach	O
.	O
</s>
<s>
In	O
practice	O
,	O
when	O
this	O
limit	O
is	O
not	O
known	O
(	O
or	O
only	O
a	O
very	O
large	O
bound	O
is	O
known	O
)	O
,	O
some	O
decision	O
has	O
to	O
be	O
made	O
in	O
the	O
implementation	O
(	O
see	O
below	O
)	O
;	O
but	O
according	O
to	O
a	O
probabilistic	O
model	O
,	O
correct	O
rounding	B-Algorithm
can	O
be	O
satisfied	O
with	O
a	O
very	O
high	O
probability	O
when	O
using	O
an	O
intermediate	O
accuracy	O
of	O
up	O
to	O
twice	O
the	O
number	O
of	O
digits	O
of	O
the	O
target	O
format	O
plus	O
some	O
small	O
constant	O
(	O
after	O
taking	O
special	O
cases	O
into	O
account	O
)	O
.	O
</s>
<s>
Some	O
programming	O
packages	O
offer	O
correct	O
rounding	B-Algorithm
.	O
</s>
<s>
The	O
GNU	B-Application
MPFR	I-Application
package	O
gives	O
correctly	O
rounded	O
arbitrary	O
precision	B-Architecture
results	O
.	O
</s>
<s>
Some	O
other	O
libraries	B-Library
implement	O
elementary	O
functions	O
with	O
correct	O
rounding	B-Algorithm
in	O
double	O
precision	B-Architecture
:	O
</s>
<s>
This	O
library	O
was	O
claimed	O
to	O
be	O
portable	O
,	O
but	O
only	O
binaries	O
for	O
PowerPC/AIX	O
,	O
SPARC/Solaris	O
and	O
x86/Windows	O
NT	O
were	O
provided	O
.	O
</s>
<s>
According	O
to	O
its	O
documentation	O
,	O
this	O
library	O
uses	O
a	O
first	O
step	O
with	O
an	O
accuracy	O
a	O
bit	O
larger	O
than	O
double	O
precision	B-Architecture
,	O
a	O
second	O
step	O
based	O
on	O
double-double	O
arithmetic	O
,	O
and	O
a	O
third	O
step	O
with	O
a	O
768-bit	O
precision	B-Architecture
based	O
on	O
arrays	O
of	O
IEEE	O
754	O
double-precision	O
floating-point	B-Algorithm
numbers	I-Algorithm
.	O
</s>
<s>
IBM	O
's	O
Accurate	O
portable	O
mathematical	O
library	O
(	O
abbreviated	O
as	O
APMathLib	O
or	O
just	O
MathLib	O
)	O
,	O
also	O
called	O
libultim	O
,	O
in	O
rounding	B-Algorithm
to	O
nearest	O
only	O
.	O
</s>
<s>
This	O
library	O
uses	O
up	O
to	O
768	O
bits	O
of	O
working	O
precision	B-Architecture
.	O
</s>
<s>
It	O
was	O
included	O
in	O
the	O
GNU	B-Language
C	I-Language
Library	I-Language
in	O
2001	O
,	O
but	O
the	O
"	O
slow	O
paths	O
"	O
(	O
providing	O
correct	O
rounding	B-Algorithm
)	O
were	O
removed	O
from	O
2018	O
to	O
2021	O
.	O
</s>
<s>
Sun	O
Microsystems	O
's	O
libmcr	O
,	O
in	O
the	O
4	O
rounding	B-Algorithm
modes	O
.	O
</s>
<s>
For	O
the	O
difficult	O
cases	O
,	O
this	O
library	O
also	O
uses	O
multiple	O
precision	B-Architecture
,	O
and	O
the	O
number	O
of	O
words	O
is	O
increased	O
by	O
2	O
each	O
time	O
the	O
Table-maker	O
'	O
s	O
dilemma	O
occurs	O
(	O
with	O
undefined	O
behavior	O
in	O
the	O
very	O
unlikely	O
event	O
that	O
some	O
limit	O
of	O
the	O
machine	O
is	O
reached	O
)	O
.	O
</s>
<s>
It	O
supports	O
the	O
4	O
rounding	B-Algorithm
modes	O
and	O
is	O
proved	O
,	O
using	O
the	O
knowledge	O
of	O
the	O
hardest-to-round	O
cases	O
.	O
</s>
<s>
The	O
CORE-MATH	O
project	O
provides	O
some	O
correctly	O
rounded	O
functions	O
in	O
the	O
4	O
rounding	B-Algorithm
modes	O
,	O
using	O
the	O
knowledge	O
of	O
the	O
hardest-to-round	O
cases	O
.	O
</s>
<s>
For	O
instance	O
,	O
if	O
Goldbach	O
's	O
conjecture	O
is	O
true	O
but	O
unprovable	O
,	O
then	O
the	O
result	O
of	O
rounding	B-Algorithm
the	O
following	O
value	O
up	O
to	O
the	O
next	O
integer	O
cannot	O
be	O
determined	O
:	O
either	O
1+10−	O
where	O
is	O
the	O
first	O
even	O
number	O
greater	O
than	O
4	O
which	O
is	O
not	O
the	O
sum	O
of	O
two	O
primes	O
,	O
or	O
1	O
if	O
there	O
is	O
no	O
such	O
number	O
.	O
</s>
<s>
The	O
value	O
before	O
rounding	B-Algorithm
can	O
however	O
be	O
approximated	O
to	O
any	O
given	O
precision	B-Architecture
even	O
if	O
the	O
conjecture	O
is	O
unprovable	O
.	O
</s>
<s>
Rounding	B-Algorithm
can	O
adversely	O
affect	O
a	O
string	O
search	O
for	O
a	O
number	O
.	O
</s>
<s>
In	O
contrast	O
,	O
truncation	B-Algorithm
does	O
not	O
suffer	O
from	O
this	O
problem	O
;	O
for	O
example	O
,	O
a	O
simple	O
string	O
search	O
for	O
"	O
3.1415	O
"	O
,	O
which	O
is	O
truncated	O
to	O
four	O
digits	O
,	O
will	O
discover	O
values	O
of	O
truncated	O
to	O
more	O
than	O
four	O
digits	O
.	O
</s>
<s>
The	O
concept	O
of	O
rounding	B-Algorithm
is	O
very	O
old	O
,	O
perhaps	O
older	O
than	O
the	O
concept	O
of	O
division	O
itself	O
.	O
</s>
<s>
The	O
origin	O
of	O
the	O
terms	O
unbiased	O
rounding	B-Algorithm
and	O
statistician	B-Algorithm
's	I-Algorithm
rounding	I-Algorithm
are	O
fairly	O
self-explanatory	O
.	O
</s>
<s>
In	O
the	O
1906	O
fourth	O
edition	O
of	O
Probability	O
and	O
Theory	B-General_Concept
of	I-General_Concept
Errors	I-General_Concept
Robert	O
Simpson	O
Woodward	O
called	O
this	O
"	O
the	O
computer	O
's	O
rule	O
"	O
indicating	O
that	O
it	O
was	O
then	O
in	O
common	O
use	O
by	O
human	O
computers	O
who	O
calculated	O
mathematical	O
tables	O
.	O
</s>
<s>
The	O
origin	O
of	O
the	O
term	O
bankers	O
 '	O
rounding	B-Algorithm
remains	O
more	O
obscure	O
.	O
</s>
<s>
If	O
this	O
rounding	B-Algorithm
method	O
was	O
ever	O
a	O
standard	O
in	O
banking	O
,	O
the	O
evidence	O
has	O
proved	O
extremely	O
difficult	O
to	O
find	O
.	O
</s>
<s>
To	O
the	O
contrary	O
,	O
section	O
2	O
of	O
the	O
European	O
Commission	O
report	O
The	O
Introduction	O
of	O
the	O
Euro	O
and	O
the	O
Rounding	B-Algorithm
of	O
Currency	O
Amounts	O
suggests	O
that	O
there	O
had	O
previously	O
been	O
no	O
standard	O
approach	O
to	O
rounding	B-Algorithm
in	O
banking	O
;	O
and	O
it	O
specifies	O
that	O
"	O
half-way	O
"	O
amounts	O
should	O
be	O
rounded	O
up	O
.	O
</s>
<s>
Until	O
the	O
1980s	O
,	O
the	O
rounding	B-Algorithm
method	O
used	O
in	O
floating-point	B-Algorithm
computer	O
arithmetic	O
was	O
usually	O
fixed	O
by	O
the	O
hardware	O
,	O
poorly	O
documented	O
,	O
inconsistent	O
,	O
and	O
different	O
for	O
each	O
brand	O
and	O
model	O
of	O
computer	O
.	O
</s>
<s>
This	O
situation	O
changed	O
after	O
the	O
IEEE	O
754	O
floating-point	B-Algorithm
standard	O
was	O
adopted	O
by	O
most	O
computer	O
manufacturers	O
.	O
</s>
<s>
The	O
standard	O
allows	O
the	O
user	O
to	O
choose	O
among	O
several	O
rounding	B-Algorithm
modes	O
,	O
and	O
in	O
each	O
case	O
specifies	O
precisely	O
how	O
the	O
results	O
should	O
be	O
rounded	O
.	O
</s>
<s>
These	O
features	O
made	O
numerical	O
computations	O
more	O
predictable	O
and	O
machine-independent	O
,	O
and	O
made	O
possible	O
the	O
efficient	O
and	O
consistent	O
implementation	O
of	O
interval	B-Algorithm
arithmetic	I-Algorithm
.	O
</s>
<s>
The	O
earliest	O
numeric	B-Algorithm
languages	O
,	O
such	O
as	O
FORTRAN	B-Application
and	O
C	B-Language
,	O
would	O
provide	O
only	O
one	O
method	O
,	O
usually	O
truncation	B-Algorithm
(	O
toward	O
zero	O
)	O
.	O
</s>
<s>
Other	O
kinds	O
of	O
rounding	B-Algorithm
had	O
to	O
be	O
programmed	O
explicitly	O
;	O
for	O
example	O
,	O
rounding	B-Algorithm
a	O
positive	O
number	O
to	O
the	O
nearest	B-Algorithm
integer	I-Algorithm
could	O
be	O
implemented	O
by	O
adding	O
0.5	O
and	O
truncating	B-Algorithm
.	O
</s>
<s>
In	O
the	O
last	O
decades	O
,	O
however	O
,	O
the	O
syntax	O
and	O
the	O
standard	O
libraries	B-Library
of	O
most	O
languages	O
have	O
commonly	O
provided	O
at	O
least	O
the	O
four	O
basic	O
rounding	B-Algorithm
functions	I-Algorithm
(	O
up	O
,	O
down	O
,	O
to	O
nearest	O
,	O
and	O
toward	O
zero	O
)	O
.	O
</s>
<s>
Several	O
languages	O
follow	O
the	O
lead	O
of	O
the	O
IEEE	O
754	O
floating-point	B-Algorithm
standard	O
,	O
and	O
define	O
these	O
functions	O
as	O
taking	O
a	O
double-precision	O
float	B-Algorithm
argument	O
and	O
returning	O
the	O
result	O
of	O
the	O
same	O
type	O
,	O
which	O
then	O
may	O
be	O
converted	O
to	O
an	O
integer	O
if	O
necessary	O
.	O
</s>
<s>
This	O
approach	O
may	O
avoid	O
spurious	O
overflows	B-Error_Name
because	O
floating-point	B-Algorithm
types	O
have	O
a	O
larger	O
range	B-Algorithm
than	O
integer	O
types	O
.	O
</s>
<s>
Some	O
languages	O
,	O
such	O
as	O
PHP	B-Application
,	O
provide	O
functions	O
that	O
round	O
a	O
value	O
to	O
a	O
specified	O
number	O
of	O
decimal	B-Application
digits	O
(	O
e.g.	O
,	O
from	O
4321.5678	O
to	O
4321.57	O
or	O
4300	O
)	O
.	O
</s>
<s>
In	O
addition	O
,	O
many	O
languages	O
provide	O
a	O
printf	B-Language
or	O
similar	O
string	O
formatting	O
function	O
,	O
which	O
allows	O
one	O
to	O
convert	O
a	O
fractional	O
number	O
to	O
a	O
string	O
,	O
rounded	O
to	O
a	O
user-specified	O
number	O
of	O
decimal	B-Architecture
places	I-Architecture
(	O
the	O
precision	B-Architecture
)	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
truncation	B-Algorithm
(	O
round	O
to	O
zero	O
)	O
is	O
still	O
the	O
default	O
rounding	B-Algorithm
method	O
used	O
by	O
many	O
languages	O
,	O
especially	O
for	O
the	O
division	O
of	O
two	O
integer	O
values	O
.	O
</s>
<s>
In	O
contrast	O
,	O
CSS	B-Language
and	O
SVG	B-Application
do	O
not	O
define	O
any	O
specific	O
maximum	O
precision	B-Architecture
for	O
numbers	O
and	O
measurements	O
,	O
which	O
they	O
treat	O
and	O
expose	O
in	O
their	O
DOM	B-General_Concept
and	O
in	O
their	O
IDL	B-General_Concept
interface	O
as	O
strings	O
as	O
if	O
they	O
had	O
infinite	B-General_Concept
precision	I-General_Concept
,	O
and	O
do	O
not	O
discriminate	O
between	O
integers	O
and	O
floating-point	B-Algorithm
values	O
;	O
however	O
,	O
the	O
implementations	O
of	O
these	O
languages	O
will	O
typically	O
convert	O
these	O
numbers	O
into	O
IEEE	O
754	O
double-precision	O
floating-point	B-Algorithm
values	O
before	O
exposing	O
the	O
computed	O
digits	O
with	O
a	O
limited	O
precision	B-Architecture
(	O
notably	O
within	O
standard	O
JavaScript	B-Language
or	O
ECMAScript	B-Language
interface	O
bindings	O
)	O
.	O
</s>
<s>
Some	O
disciplines	O
or	O
institutions	O
have	O
issued	O
standards	O
or	O
directives	O
for	O
rounding	B-Algorithm
.	O
</s>
<s>
This	O
notation	O
is	O
used	O
when	O
the	O
negative	O
sign	O
is	O
considered	O
important	O
,	O
no	O
matter	O
how	O
small	O
is	O
the	O
magnitude	O
;	O
for	O
example	O
,	O
when	O
rounding	B-Algorithm
temperatures	O
in	O
the	O
Celsius	B-Operating_System
scale	O
,	O
where	O
below	O
zero	O
indicates	O
freezing	O
.	O
</s>
