Skip to main content

Variety of rounding methods and implementations

Project description

Rounding methods

StandardRound rounds to the nearest, and in the event of a tie, rounds up.

RoundToEven rounds to the nearest, but in the event of a tie, rounds toward the nearest even number.

StochasticRound provides a mechanism to eliminate accumulated roundoff error in the presence of a distribution where for individual samples, the roundoff error is skewed. This is typically caused by small values. This may be a common problem when dealing with applying a function to many small integer values as the number of discreet inputs is small.

One drawback to stochastic rounding is the output is non-deterministic, but this can be avoided by providing a custom deterministic generator, or invoking providing the random number generator with a fixed seed.

r = random.Random()
r.seed(123)
sr = StochasticRound(precision=0, random_generator=r)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rounding-0.4.tar.gz (2.8 kB view details)

Uploaded Source

File details

Details for the file rounding-0.4.tar.gz.

File metadata

  • Download URL: rounding-0.4.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for rounding-0.4.tar.gz
Algorithm Hash digest
SHA256 a71f3bd0d67558b0e71eb65c870c4ca9bb8f7c85f1607715f4197d010dc3968f
MD5 6eb90ca395157b9b8825df2bb3cfa935
BLAKE2b-256 a1ebeda05aec16c32631a4a66711e697fccfb9267ee11bf16dd90a0567087a6b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page