# Num

[![Pylint](https://github.com/Tini4/Num/actions/workflows/pylint.yml/badge.svg)](https://github.com/Tini4/Num/actions/workflows/pylint.yml)
[![CodeCov](https://codecov.io/gh/Tini4/Num/branch/master/graph/badge.svg?token=BILTI4331O)](https://codecov.io/gh/Tini4/Num)

Python precise number type.

[![CC BY-NC-ND](https://i.creativecommons.org/l/by-nc-nd/4.0/88x31.png)](http://creativecommons.org/licenses/by-nc-nd/4.0/)

## Why?

Because float:
```python
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

```python
# Import the Num class
from src.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
```

## 1
- http://www.java2s.com/Tutorials/Python/Class/Overload_divide_operator.htm
- https://www.geeksforgeeks.org/operator-overloading-in-python/

## 2
- https://t5k.org/lists/small/millions/
- https://t5k.org/notes/faq/LongestList.html
- http://compoasso.free.fr/primelistweb/page/prime/liste_online_en.php

## 3
- https://www.sphinx-doc.org/en/master/usage/quickstart.html
- https://towardsdatascience.com/documenting-python-code-with-sphinx-554e1d6c4f6d

## 4
- https://stackoverflow.com/questions/53668052/sphinx-cannot-find-my-python-files-says-no-module-named

## 5
- https://stackoverflow.com/questions/26344081/efficient-prime-factorization-for-large-numbers#26344929

make html
make clean html

* https://www.freecodecamp.org/news/how-to-create-and-upload-your-first-python-package-to-pypi/
