Python precise number type.
Project description
Num
Python precise number type.
Why?
Because float:
print(0.1 * 3.0) # 0.30000000000000004
print(0.3) # 0.3
print(0.1 * 3.0 == 0.3) # False
Installation
pip install num-tini4
Usage
# Import the Num class
from num_tini4.num import Num
# Declare variables
num1: Num = Num()
num2: Num = Num()
# Define variables
num1.set_fraction(1, 11) # 1/11
num2.set_int(-18) # -18
print(num1) # [NUMBER, POSITIVE, {11: -1}]
print(num2) # [NUMBER, NEGATIVE, {2: 1, 3: 2}]
print(repr(num1)) # Num(primes={11: -1}, sign=<Sign.POSITIVE: 1>, case=<Case.NUMBER: 1>)
print(repr(num2)) # Num(primes={2: 1, 3: 2}, sign=<Sign.NEGATIVE: -1>, case=<Case.NUMBER: 1>)
print(float(num1)) # 0.09090909090909091
print(float(num2)) # -18.0
# Arithmetic Operators
print((num1 + num2).get_fraction()) # (-197, 11)
print((num1 + num2).get_float()) # -17.90909090909091
print((1 / 11) + -18.0) # -17.90909090909091
print('--------------------------------------------------')
print((num1 - num2).get_fraction()) # (199, 11)
print((num1 - num2).get_float()) # 18.09090909090909
print((1 / 11) - -18.0) # 18.09090909090909
print('--------------------------------------------------')
print((num1 * num2).get_fraction()) # (-18, 11)
print((num1 * num2).get_float()) # -1.6363636363636365
print((1 / 11) * -18.0) # -1.6363636363636365
print('--------------------------------------------------')
print((num1 / num2).get_fraction()) # (-1, 198)
print((num1 / num2).get_float()) # -0.00505050505050505
print((1 / 11) / -18.0) # -0.005050505050505051
print('--------------------------------------------------')
# todo: Assignment Operators
# +=, -=, *=, /=
# todo: Comparison Operators
# <, >, <=, >=, ==, !=
# Other
# -, abs(), float()
# Inaccurate!!! Slow!!! Avoid!!!
num1.set_float(18 / 11)
print(num1) # [NUMBER, POSITIVE, {2: -52, 19: 1, 26041: 1, 14894582557: 1}]
print(num1.get_fraction()) # (7369526662969903, 4503599627370496)
print(num1.get_float()) # 1.6363636363636365
print(18 / 11) # 1.6363636363636365
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
num_tini4-0.2.0a1.tar.gz
(2.1 MB
view details)
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 num_tini4-0.2.0a1.tar.gz.
File metadata
- Download URL: num_tini4-0.2.0a1.tar.gz
- Upload date:
- Size: 2.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91d1664ad0c73d73081384071f9bdcb26fd746a7273ac14b6c29fda42846ecec
|
|
| MD5 |
1aeb91ea7075a951cd11571b6887bf36
|
|
| BLAKE2b-256 |
dc67671c9146a733de62afc8a70ab10fca14d95d2499f595f696683a171f7e3e
|
File details
Details for the file num_tini4-0.2.0a1-py3-none-any.whl.
File metadata
- Download URL: num_tini4-0.2.0a1-py3-none-any.whl
- Upload date:
- Size: 2.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c43079473607af19d3bbaa7d3552a3e74a2675d0886fa45f7cbcb10beced8a5
|
|
| MD5 |
9da67f3a33223f0692fe226dd12c3536
|
|
| BLAKE2b-256 |
38c1c97fdfc1c7df700bcee0542c58ac85738ebc1ecd8b249fb21b12d5dc0cf3
|