The effective propagation of accumulated roundoff errors may depend on the discrete dimension of the sampled data to round: when sampling bidimensional images, including colored images (that add the discrete dimension of color planes), or tridimensional videos (that add a discrete time dimension), or on polyphonic audio data (using time and channel discrete dimensions), it may still be preferable to propagate this error into a preferred direction, or equally into several orthogonal dimensions, such as vertically vs. horizontally for bidimensional images, or into parallel color channels at the same position and/or timestamp, and depending on other properties of these orthogonal discrete dimensions (according to a perception model). In those cases, several roundoff error accumulators may be used (at least one for each discrete dimension), or a ("n"-1)-dimension vector (or matrix) of accumulators.
In some of these cases, the discrete dimensions of the data to sample and round may be treated non orthogonally: for example, when working with colored images, the trichromatic color planes data in each physical dimension (height, width and optionally time) could be remapped using a perceptive color model, so that the roundoff error accumulators will be designed to preserve lightness with a higher probability than hue or saturation, instead of propagating errors into each orthogonal color plane independently; and in stereophonic audio data the two rounded data channels (left and right) may be rounded together to preserve their mean value in priority to their effective difference that will absorb most of the remaining roundoff errors, in a balanced way around zero.
In some contexts it is desirable to round a given number "x" to a "neat" fraction — that is, the nearest fraction "z" = "m"/"n"
whose numerator "m" and denominator "n" do not exceed a given maximum. This problem is fairly distinct from that of rounding a value to a fixed number of decimal or binary digits, or to a multiple of a given unit "m". This problem is related to Farey sequences, the Stern-Brocot tree, and continued fractions.
This type of rounding, which is also named rounding to a logarithmic scale, is a variant of Rounding to a specified increment but with an increment that is modified depending on the scale and magnitude of the result. Concretely, the intent is to limit the number of significant digits, rounding the value so that non-significant digits will be dropped. This type of rounding occurs implicitly with numbers computed with floating-point values with limited precision (such as IEEE-754 "float" and "double" types), but it may be used more generally to round any real values with any positive number of significant digits and any strictly positive real base.
For example it can be used in engineering graphics for representing data with a logarithmic scale with variable steps (for example wave lengths, whose base is not necessarily an integer measure), or in statistical data to define classes of real values within intervals of exponentially growing widths (but the most common use is with integer bases such as 10 or 2).
This type of rounding is based on a logarithmic scale defined by a fixed non-zero real scaling factor "s" (in most frequent cases this factor is "s"=1) and a fixed positive base "b">1 (not necessarily an integer and most often different from the scaling factor), and a fixed integer number "n">0 of significant digits in that base (which will determine the value of the increment to use for rounding, along with the computed effective scale of the rounded number).
The primary argument number (as well as the resulting rounded number) is first represented in exponential notation "x" = "s"·"a"·"m"·"b", such that the sign "s" is either +1 or −1, the absolute mantissa "a" is restricted to the half-open positive interval [1/"b",1), and the exponent "c" is any (positive or negative) integer. In that representation, all significant digits are in the fractional part of the absolute mantissa whose integer part is always zero.
If the source number (or rounded number) is 0, the absolute mantisssa "a" is defined as 0, the exponent "c" is fixed to an arbitrary value (0 in most conventions, but some floating-point representations cannot use a null absolute mantissa but reserve a specific maximum negative value for the exponent "c" to represent the number 0 itself), and the sign "s" may be arbitrarily chosen between −1 or +1 (it is generally set to +1 for simple zero, or it is set to the same sign as the argument in the rounded value if the number representation allows to differentiate positive and negative zeroes, even if they finally represent the same numeric value 0).
A scaled exponential representation as "x" = "a"·"s"·"b" may also be used equivalently, with a signed mantissa "a" either equal to zero or within one of the two half-open intervals (−1,−1/"b"] and [+1/"b",+1), and this will be the case in the algorithm below.
The steps to compute this scaled rounding are generally similar to the following:
For the abstract "round()" function, this type of rounding can use any one of the "rounding to integer" modes described more completely in the next section, but it is most frequently the "round to nearest" mode (with tie-breaking rules also described more completely below).
For example:
Finished lumber, writing paper, capacitors, and many other products are usually sold in only a few standard sizes.
Many design procedures describe how to calculate an approximate value, and then "round" to some standard size using phrases such as "round down to nearest standard value", "round up to nearest standard value", or "round to nearest standard value".
When a set of preferred values is equally spaced on a logarithmic scale,
Choosing the closest preferred value to any given value can be seen as a kind of scaled rounding.
Such "rounded" values can be directly calculated.
In floating-point arithmetic, rounding aims to turn a given value "x" into a value "z" with a specified number of "significant" digits. In other words, "z" should be a multiple of a number "m" that depends on the magnitude of "z". The number "m" is a power of the base (usually 2 or 10) of the floating-point form.
Apart from this detail, all the variants of rounding discussed above apply to the rounding of floating-point numbers as well. The algorithm for such rounding is presented in the Scaled rounding section above, but with a constant scaling factor "s"=1, and an integer base "b">1.
For results where the rounded result would overflow the result for a directed rounding is either the appropriate signed infinity, or the highest representable positive finite number (or the lowest representable negative finite number if "x" is negative), depending on the direction of rounding. The result of an overflow for the usual case of "round to even" is always the appropriate infinity.
In addition, if the rounded result would underflow, i.e. if the exponent would exceed the lowest representable integer value, the effective result may be either zero (possibly signed if the representation can maintain a distinction of signs for zeroes), or the smallest representable positive finite number (or the highest representable negative finite number if "x" is negative), possibly a "denormal" positive or negative number (if the mantissa is storing all its significant digits, in which case the most significant digit may still be stored in a lower position by setting the highest stored digits to zero, and this stored mantissa does not drop the most significant digit, something that is possible when base "b"=2 because the most significant digit is always 1 in that base), depending on the direction of rounding. The result of an underflow for the usual case of "round to even" is always the appropriate zero.