Round
Rounds x to the nearest integer, or to the nearest multiple of a.
✓ checked against that system · ! checked, with disagreements (hover a chip)Wikipedia
RoundingMathWorldNearestIntegerFunctionRoundingWikidataQ663208Wolfram LanguageRound✓Round(x)rounds x to the nearest integer, a tie to the even one.SageMath
round(x)SymPyround(x)mpmathnint(x)Juliaenumeratio_round(x)Rustround(x)Round(x, a)rounds to the nearest multiple of the step a.Round(x, a?)Rounds x to the nearest integer, or to the nearest multiple of a.Typed signatures
| Type | Package | Applies |
|---|---|---|
(x: real | signed_infinity | ~oo, step: real?) -> real | signed_infinity | ~oo | analyticreplaces compute-engine | always |
(x: real | signed_infinity | ~oo, step: real?) -> real | signed_infinity | ~oo | compute-engine | always |
(any, any?) -> any | structuresreplaces analytic | always |
Details
- Rounds to the nearest integer, with ties (an exact .5) going to the even one, as in Wolfram, Sage, SymPy, mpmath and Python: , and .
- A second argument a rounds to the nearest multiple of a, as in Wolfram: and . A step of 1 agrees with the 1-argument form.
- Threads element-wise over a list.
- Floor and Ceil take a step the same way.
- Differs from Rust's
round, and from compute-engine's own default, in the tie rule: both send a tie away from zero, so there where it is here. Only exact ties differ. - Python's
round(x, n)counts digits: itsround(x, 2)is here. - Ties follow the engine's
roundingTiessetting, which every engine we ship sets toto-even; compute-engine's default is away from zero.
Examples
3 more kept as data, checked against the oraclesScope #
Properties #
Possible issues #
Round(ComplexInfinity) is ComplexInfinity: rounding an infinite magnitude with no direction is still that magnitude, the same convention as Ceil and Floor
live ↗InOut
Known value · Wolfram Round[ComplexInfinity]
About
| Examples | 27 |
|---|---|
| Checked against | Wolfram Language 27 agreeSageMath 16 agree4 errorSymPy 25 agree2 errormpmath 17 agreeJulia 17 agreeRust 11 agree5 differ |
| Crosswalk | WikipediaMathWorld ×2WikidataWolfram LanguageSageMathSymPympmathJuliaRust |
Implementation
mapped
sympypackages/oracle/src/mappings.tsSymPy's round, like Wolfram's, sends a tie to the even integer and rounds a complex number part by part.
mapped
sympypackages/oracle/src/mappings.tsmapped
mpmathpackages/oracle/src/mappings.tsmpmath rounds half to even.
mapped
sagepackages/oracle/src/mappings.tsmapped
juliapackages/oracle/src/mappings.tsmapped
rustpackages/oracle/src/mappings.tsTies go away from zero, as num-rational's round and std's do.