Skip to content

Commit aef5451

Browse files
committed
2 parents d7964de + 5272ee1 commit aef5451

2 files changed

Lines changed: 197 additions & 0 deletions

File tree

.gitignore

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
.pytest_cache/
49+
50+
# Translations
51+
*.mo
52+
*.pot
53+
54+
# Django stuff:
55+
*.log
56+
local_settings.py
57+
db.sqlite3
58+
59+
# Flask stuff:
60+
instance/
61+
.webassets-cache
62+
63+
# Scrapy stuff:
64+
.scrapy
65+
66+
# Sphinx documentation
67+
docs/_build/
68+
69+
# PyBuilder
70+
target/
71+
72+
# Jupyter Notebook
73+
.ipynb_checkpoints
74+
75+
# pyenv
76+
.python-version
77+
78+
# celery beat schedule file
79+
celerybeat-schedule
80+
81+
# SageMath parsed files
82+
*.sage.py
83+
84+
# Environments
85+
.env
86+
.venv
87+
env/
88+
venv/
89+
ENV/
90+
env.bak/
91+
venv.bak/
92+
93+
# Spyder project settings
94+
.spyderproject
95+
.spyproject
96+
97+
# Rope project settings
98+
.ropeproject
99+
100+
# mkdocs documentation
101+
/site
102+
103+
# mypy
104+
.mypy_cache/

README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,96 @@ Complex class for different operations on complex numbers.
55
- This class is essentially for mathematical operations on complex numbers.
66
- It is very easy and intuitif to use, as any mathematicain would expect.
77
- There is more to come on this class, like power of complex numbers.
8+
9+
## Installation
10+
11+
Use the package manager [pip](https://pypi.org/project/cmpx/) to install cmpx.
12+
13+
```bash
14+
pip install cmpx
15+
```
16+
17+
## Usage
18+
### Importing Complex class
19+
```python
20+
from cmpx.Complex import Complex
21+
```
22+
### Different instanciations of Complex class
23+
```python
24+
# Instanciation 1
25+
number = Complex() # --> Real = 0, Imaginary = 0
26+
print(number)
27+
# Instanctiation 2
28+
number = Complex(42) # --> Real = 42, Imaginary = 0
29+
print(number)
30+
# Instanciation 3
31+
number = Complex(12, -3.2) # --> Real = 12, Imaginary = -3.2
32+
print(number)
33+
# Instanciation 4
34+
number = Complex(im=13.2, re=5) # --> Real = 5, Imaginary = 13.2
35+
print(number)
36+
# Instanciation 5
37+
number = Complex(re=3, im=-2.4, restore=False) # restore argument is by default True, whenever an error occurs on operation, the last result will be restored to the object, else if it is False then the object will be simply None.
38+
```
39+
### Basic operations
40+
```python
41+
num1 = Complex(re=3, im=-2.5)
42+
num2 = Complex(re=4.2, im=13.2)
43+
# Summation
44+
print('({}) + ({}) = {}'.format(num1, num2, num1 + num2))
45+
# Substraction
46+
print('({}) - ({}) = {}'.format(num1, num2, num1 - num2))
47+
# Multiplication
48+
print('({}) * ({}) = {}'.format(num1, num2, num1 * num2))
49+
# Division
50+
print('({}) / ({}) = {}'.format(num1, num2, num1 / num2))
51+
# Floor division
52+
print('({}) // ({}) = {}'.format(num1, num2, num1 // num2))
53+
## Affecting the result directly on the number
54+
# Summation
55+
print('({}) += ({})'.format(num1, 2), end=' --> ')
56+
num1 += 2
57+
print(num1)
58+
# Substraction
59+
print('({}) -= ({})'.format(num1, num2), end=' --> ')
60+
num1 -= num2
61+
print(num1)
62+
# Multiplication
63+
print('({}) *= ({})'.format(num1, 2), end=' --> ')
64+
num1 *= 2
65+
print(num1)
66+
# Division
67+
print('({}) /= ({})'.format(num1, num2), end=' --> ')
68+
num1 /= num2
69+
print(num1)
70+
# Floor division
71+
print('({}) //= ({})'.format(num1, 2), end=' --> ')
72+
num1 /= 2
73+
print(num1)
74+
# Congugated of a complex number
75+
print('con({}) = {}'.format(num2, num2.con()))
76+
# Module of a complex number
77+
print('mod({}) = {}'.format(num2, num2.mod()))
78+
```
79+
### Comparisons of Complex numbers
80+
```python
81+
num1 = Complex(im=3.1, re=-5)
82+
num2 = Complex(im=-1.5, re=0.6)
83+
# Greater than
84+
if(num1 > num2): print('({}) > ({})'.format(num1, num2))
85+
# Greater or equal
86+
if(num1 >= num2): print('({}) >= ({})'.format(num1, num2))
87+
# Less than
88+
if(num1 < num2): print('({}) < ({})'.format(num1, num2))
89+
# Less or equal
90+
if(num1 <= num2): print('({}) <= ({})'.format(num1, num2))
91+
# Equal
92+
if(num1 == num2): print('({}) == ({})'.format(num1, num2))
93+
# Not equal
94+
if(num1 != num2): print('({}) != ({})'.format(num1, num2))
95+
```
96+
97+
## Contributing
98+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
99+
100+
Please make sure to update tests as appropriate.

0 commit comments

Comments
 (0)