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 other values== ===Rounding to a specified multiple=== The most common type of rounding is to round to an integer; or, more generally, to an integer multiple of some increment – such as rounding to whole tenths of seconds, hundredths of a dollar, to whole multiples of 1/2 or 1/8 inch, to whole dozens or thousands, etc. In general, rounding a number {{mvar|x}} to a multiple of some specified positive value {{mvar|m}} entails the following steps: :<math>\mathrm{roundToMultiple}(x, m) = \mathrm{round}(x/m) \times m</math> For example, rounding {{math|1=''x'' = 2.1784}} dollars to whole cents (i.e., to a multiple of 0.01) entails computing {{math|1=2.1784 / 0.01 = 217.84}}, then rounding that to 218, and finally computing {{math|1=218 × 0.01 = 2.18}}. When rounding to a predetermined number of [[significant figures|significant digits]], the increment {{mvar|m}} depends on the magnitude of the number to be rounded (or of the rounded result). The increment {{mvar|m}} is normally a finite fraction in whatever [[numeral system]] is used to represent the numbers. For display to humans, that usually means the [[decimal|decimal numeral system]] (that is, {{mvar|m}} is an integer times a [[power (mathematics)|power]] of 10, like 1/1000 or 25/100). For intermediate values stored in digital computers, it often means the [[binary number|binary numeral system]] ({{mvar|m}} is an integer times a power of 2). The abstract single-argument "round()" function that returns an integer from an arbitrary real value has at least a dozen distinct concrete definitions presented in the [[#Rounding to integer|rounding to integer]] section. The abstract two-argument "roundToMultiple()" function is formally defined here, but in many cases it is used with the implicit value {{math|1=''m'' = 1}} for the increment and then reduces to the equivalent abstract single-argument function, with also the same dozen distinct concrete definitions. ===Logarithmic rounding=== ====Rounding to a specified power==== Rounding to a specified ''power'' is very different from rounding to a specified ''multiple''; for example, it is common in computing to need to round a number to a whole power of 2. The steps, in general, to round a positive number {{mvar|x}} to a power of some positive number {{mvar|b}} other than 1, are: :<math>\mathrm{roundToPower}(x, b) = b^{\mathrm{round}(\log_b x)}, x>0, b>0, b \ne 1</math> Many of the caveats applicable to rounding to a multiple are applicable to rounding to a power. ====Scaled rounding==== This type of rounding, which is also named '''rounding to a logarithmic scale''', is a variant of [[#Rounding to a specified power|rounding to a specified power]]. Rounding on a logarithmic scale is accomplished by taking the log of the amount and doing normal rounding to the nearest value on the log scale. For example, resistors are supplied with [[preferred number]]s on a logarithmic scale. In particular, for resistors with a 10% accuracy, they are supplied with nominal values 100, 120, 150, 180, 220, etc. rounded to multiples of 10 ([[E12 series]]). If a calculation indicates a resistor of 165 ohms is required then {{math|1=log(150) = 2.176}}, {{math|1=log(165) = 2.217}} and {{math|1=log(180) = 2.255}}. The logarithm of 165 is closer to the logarithm of 180 therefore a 180 ohm resistor would be the first choice if there are no other considerations. Whether a value {{math|''x'' ∈ (''a'', ''b'')}} rounds to {{mvar|a}} or {{mvar|b}} depends upon whether the squared value {{math|''x''{{sup|2}}}} is greater than or less than the product {{math|''ab''}}. The value 165 rounds to 180 in the resistors example because {{math|1=165{{sup|2}} = 27225}} is greater than {{math|1=150 × 180 = 27000}}. ===Floating-point rounding=== In [[floating-point arithmetic]], rounding aims to turn a given value {{mvar|x}} into a value {{mvar|y}} with a specified number of {{em|significant}} digits. In other words, {{mvar|y}} should be a multiple of a number {{mvar|m}} that depends on the magnitude of {{mvar|x}}. The number {{mvar|m}} is a power of the [[radix|base]] (usually 2 or 10) of the floating-point representation. 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|Scaled rounding]] section above, but with a constant scaling factor {{math|1=''s'' = 1}}, and an integer base {{math|''b'' > 1}}. Where the rounded result would overflow the result for a directed rounding is either the appropriate signed infinity when "rounding away from zero", or the highest representable positive finite number (or the lowest representable negative finite number if {{mvar|x}} is negative), when "rounding toward zero". The result of an overflow for the usual case of ''round to nearest'' is always the appropriate infinity. ===Rounding to a simple fraction=== In some contexts it is desirable to round a given number {{mvar|x}} to a "neat" fraction – that is, the nearest fraction {{math|1=''y'' = ''m''/''n''}} whose numerator {{mvar|m}} and denominator {{mvar|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 {{mvar|m}}. This problem is related to [[Farey sequence]]s, the [[Stern–Brocot tree]], and [[continued fraction]]s. ===Rounding to an available value=== Finished [[lumber]], writing paper, electronic components, and many other products are usually sold in only a few standard values. 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".<ref>{{cite web |title=Zener Diode Voltage Regulators |url=https://www.kennethkuhn.com/students/ee431/voltage_regulators_zeners.pdf |access-date=2010-11-24 |url-status=live |archive-url=https://web.archive.org/web/20110713143253/http://www.kennethkuhn.com/students/ee431/text/voltage_regulators_zeners.pdf |archive-date=2011-07-13}}</ref><ref>[https://stellafane.org/tm/atm/test/tester-3.html "Build a Mirror Tester"]</ref> When a set of [[preferred value]]s is equally spaced on a logarithmic scale, choosing the closest [[preferred value]] to any given value can be seen as a form of [[#Scaled rounding|scaled rounding]]. Such rounded values can be directly calculated.<ref>Bruce Trump, Christine Schneider. "Excel Formula Calculates Standard 1%-Resistor Values". [[Electronic Design]], 2002-01-21. [https://www.electronicdesign.com/components/excel-formula-calculates-standard-1-resistor-values]</ref> === Arbitrary bins === More general rounding rules can separate values at arbitrary break points, used for example in [[data binning]]. A related mathematically formalized tool is [[signpost sequence]]s, which use notions of distance other than the simple difference – for example, a sequence may round to the integer with the smallest ''relative'' (percent) error.
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