Rounding

Rounding is almost unavoidable when reporting many computations – especially when dividing two numbers in integer or fixed-point arithmetic; when computing mathematical functions such as square roots, logarithms, and sines; or when using a floating-point representation with a fixed number of significant digits.

In a sequence of calculations, these rounding errors generally accumulate, and in certain ill-conditioned cases they may make the result meaningless.

Rounding has many similarities to the quantization that occurs when physical quantities must be encoded by numbers or digital signals.

It was initially set at 1000.000 (three decimal places of accuracy), and after 22 months had fallen to about 520, although the market appeared to be rising.

[4][5] This method only requires checking one digit to determine rounding direction in two's complement and similar representations.

[7] This is the default rounding mode used in IEEE 754 operations for results in binary floating-point formats.

This variant is almost never used in computations, except in situations where one wants to avoid increasing the scale of floating-point numbers, which have a limited exponent range.

Effectively, this mode prefers preserving the existing scale of tie numbers, avoiding out-of-range results when possible for numeral systems of even radix (such as binary and decimal).

Like round-half-to-even and round-half-to-odd, this rule is essentially free of overall bias, but it is also fair among even and odd y values.

For example, suppose one started with 0 and added 0.3 to that one hundred times while rounding the running total between every addition.

For display to humans, that usually means the decimal numeral system (that is, m is an integer times a power of 10, like 1/1000 or 25/100).

For intermediate values stored in digital computers, it often means the binary numeral system (m is an integer times a power of 2).

Finished lumber, writing paper, electronic components, and many other products are usually sold in only a few standard values.

[13] More general rounding rules can separate values at arbitrary break points, used for example in data binning.

A related technique called pulse-width modulation is used to achieve analog type output from an inertial device by rapidly pulsing the power with a variable duty cycle.

[14] It is possible to use rounded arithmetic to evaluate the exact value of a function with integer domain and range.

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.

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.

Even the fact (if true) that a finite number of extra digits will ultimately suffice may be a deep theorem.

[24] In practice, when this limit is not known (or only a very large bound is known), some decision has to be made in the implementation (see below); but according to a probabilistic model, correct rounding can be satisfied with a very high probability when using an intermediate accuracy of up to twice the number of digits of the target format plus some small constant (after taking special cases into account).

The GNU MPFR package gives correctly rounded arbitrary precision results.

Some ancient clay tablets found in Mesopotamia contain tables with rounded values of reciprocals and square roots in base 60.

For example, Jörg Baten used age heaping in many studies, to evaluate the numeracy level of ancient populations.

He came up with the ABCC Index, which enables the comparison of the numeracy among regions possible without any historical sources where the population literacy was measured.

[47] Most programming languages provide functions or special syntax to round fractional numbers in various ways.

In the last decades, however, the syntax and the standard libraries of most languages have commonly provided at least the four basic rounding functions (up, down, to nearest, and toward zero).

Several languages follow the lead of the IEEE 754 floating-point standard, and define these functions as taking a double-precision float argument and returning the result of the same type, which then may be converted to an integer if necessary.

Some languages, such as PHP, provide functions that round a value to a specified number of decimal digits (e.g., from 4321.5678 to 4321.57 or 4300).

In contrast, CSS and SVG do not define any specific maximum precision for numbers and measurements, which they treat and expose in their DOM and in their IDL interface as strings as if they had infinite precision, and do not discriminate between integers and floating-point values; however, the implementations of these languages will typically convert these numbers into IEEE 754 double-precision floating-point values before exposing the computed digits with a limited precision (notably within standard JavaScript or ECMAScript[48] interface bindings).

This notation is used when the negative sign is considered important, no matter how small is the magnitude; for example, when rounding temperatures in the Celsius scale, where below zero indicates freezing.

Graphs of the result, y , of rounding x using different methods. For clarity, the graphs are shown displaced from integer y values. In the SVG file, hover over a method to highlight it and, in SMIL -enabled browsers, click to select or deselect it.