Skip to main content

Large numbers with high precision

Project description

Vinculum

codecov

Vinculum is a Python package for handling large numbers with high precision.

Examples

Numbers are recorded as rational fractions rather than floating-point decimals, so 1.2 - 1.0 really does equal 0.2.

Using native float:

a = 1.2
b = 1.0
c = a - b

print(c)  # 0.19999999999999996

Using Vinculum Rational:

from vinculum import Rational

a = Rational.from_float(1.2)
b = Rational.from_float(1.0)
c = a - b

print(c)            # 1/5
print(c.decimal())  # 0.2

A Rational can be rendered to any arbitrary number of decimal places, but repeating digits will be noted and rendered with overhead dots:

from vinculum import Rational

print(Rational(1146408, 364913).decimal(max_dp=999))
# 3.141592653591403978482542414219279663919893234825835199074847977463121346731
# 96076873117702027606580198567877822933137487565529317947017508282796173334466
# 02340831924321687635134949974377454352133248198885761811719505745205021470871
# 13914823533280535360483183662955279751612028072444664892727855680669090988811
# 03167056257244877546154836906331098097354711945038954490522398489502977422015
# 65852682694231227717291518800371595421374409790826854620142335296358310062946
# 51053812826618947529959195753508370488308172084853101972250920082320991578814
# 67637491676098138460400150172780909422245850380775691740223012060408919386264
# 67130521521568154601233718721996749910252580752124478985401999928750140444434
# 70087390693124114514966581075489226199121434424095606350006713929073505191648
# 42030840227670705072167886592146621249448498683247787828879760381241556206547
# 86209315645098968795301893876074571199162540112300740176425613776434382989918
# 14487288751017365783077062203867771222181725507175682971009528298525950020963

print(Rational(1, 3).decimal())
# 0.̇3

Note that the latter output is 0.̇3 with a dot and not 0.3.

Full documentation is online at cariad.github.io/vinculum.

Installation

Vinculum requires Python 3.11 or later:

pip install vinculum

Support

Please raise bugs, feature requests and ask questions at github.com/cariad/vinculum/issues.

The Project

Vinculum is © 2022-2023 Cariad Eccleston and released under the MIT License at github.com/cariad/vinculum.

The Author

Hello! 👋 I'm Cariad Eccleston and I'm a freelance backend and infrastructure engineer in the United Kingdom. You can find me at cariad.earth, github/cariad, linkedin/cariad and on the Fediverse at @cariad@hachyderm.io.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

vinculum-1.0.0b12-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file vinculum-1.0.0b12-py3-none-any.whl.

File metadata

  • Download URL: vinculum-1.0.0b12-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for vinculum-1.0.0b12-py3-none-any.whl
Algorithm Hash digest
SHA256 03126cf9641ad21dcd0ed00b8880589d8b27ab3ccdcb1db8f3a20b1b815b718f
MD5 bc31fce0b1aacda6a6d2c0dfdfa7d0d6
BLAKE2b-256 afacf10409357517a3be051343b57eb1bd74648ce2e81a4f143072b330432232

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