Arbitrary precision decimal numbers
Project description
Arbitrary precision decimal numbers
A module with a simple implementation for arbitrary precision
decimal numbers. The key difference to most other decimal
libraries is that there is no maximum precision for example
when doing divisions.
>>> from dezimal import Dezimal
>>> Dezimal("355") / Dezimal("113")
Dezimal('3.14159292035398230088495575221238938053097345132743362831858407079646017699115044247787610619469026548672566371681')
dezimal will calculate as many digits after the decimal point as
there are, no ROUNDING_MODE or whatever needed.
If the calculation
would result in a period, dezimal detects that and stops the calculation
as needed:
>>> Dezimal("1") / Dezimal("7")
Dezimal('0.14285714285714285')
However, it prints a minimum number of digits, as to display at least
the same precision as a regular float would (a bit more actually).
>>> Dezimal("1") / Dezimal("3")
Dezimal('0.33333333333333333')
>>> 1.0 / 3.0
0.3333333333333333
These parameters can be controlled by invoking the static div
method in Dezimal directly:
>>> Dezimal.div(Dezimal("1"), Dezimal("3"), minscale=5)
Dezimal('0.33333')
Also a maximum precision can be given:
>>> Dezimal.div(Dezimal("355"), Dezimal("113"), maxscale=30)
Dezimal('3.141592920353982300884955752212')
Construction
An instance of Dezimal can be constructed from int, float, bool,
or a str. The usual formats like 3, 3.0, 7e1, -7e-9, or
+13.03e-3 are understood.
Supported operations
The following operations are supported:
+ - * / // < <= > >= == !=
Why?
For fun.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dezimal-0.4.0.tar.gz.
File metadata
- Download URL: dezimal-0.4.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f66cd7f11fab42b12ad2e59ac0061f5da355cb3bee0d6d2737c5b6a8fd8f1062
|
|
| MD5 |
88e8d52aed000359beb0736985237ddd
|
|
| BLAKE2b-256 |
3c18d8beb65925335a1d5d150df4ec570f1e6906cf6912ad8b2af11b06916b43
|
File details
Details for the file dezimal-0.4.0-py3-none-any.whl.
File metadata
- Download URL: dezimal-0.4.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9dee9360aaf26903f7fbed088311a69ce5277629daf722b9c7e47d6c471fe19
|
|
| MD5 |
d5db1619a5f42e335d2791821c15a48e
|
|
| BLAKE2b-256 |
b7d5b9b90e7f35e8fb9c0c5b51137da1bef3bf4cb79259c86c303f7d9750ae30
|