Skip to content

Commit 48c076e

Browse files
committed
Adding package to pypi
1 parent 9ae0175 commit 48c076e

12 files changed

Lines changed: 196 additions & 0 deletions

File tree

File renamed without changes.

build/lib/cmpx/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from . import Complex
2+
3+
__all__ = [
4+
'Complex'
5+
]

cmpx.egg-info/PKG-INFO

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Metadata-Version: 2.1
2+
Name: cmpx
3+
Version: 0.2
4+
Summary: Complex class for different operations on complex numbers
5+
Home-page: https://github.com/Omar-Belghaouti/PythonComplex
6+
Author: Omar Belghaouti
7+
Author-email: bel_omar18@yahoo.com
8+
License: MIT
9+
Download-URL: https://pypi.org/project/cmpx/
10+
Description: # PythonComplex
11+
Complex class for different operations on complex numbers.
12+
13+
## More details
14+
- This class is essentially for mathematical operations on complex numbers.
15+
- It is very easy and intuitif to use, as any mathematicain would expect.
16+
- There is more to come on this class, like power of complex numbers.
17+
18+
Keywords: Complex,ComplexOperations,ComplexNumbers
19+
Platform: UNKNOWN
20+
Description-Content-Type: text/markdown

cmpx.egg-info/SOURCES.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
README.md
2+
setup.py
3+
cmpx/Complex.py
4+
cmpx/__init__.py
5+
cmpx.egg-info/PKG-INFO
6+
cmpx.egg-info/SOURCES.txt
7+
cmpx.egg-info/dependency_links.txt
8+
cmpx.egg-info/top_level.txt

cmpx.egg-info/dependency_links.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

cmpx.egg-info/top_level.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cmpx

cmpx/Complex.py

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Sep 10 17:36:25 2019
4+
5+
@author: Omar Belghaouti
6+
"""
7+
from math import sqrt
8+
# Complex class for complex number manipulations
9+
class Complex():
10+
# Constructor
11+
def __init__(self, re=0, im=0):
12+
self.re = re
13+
self.im = im
14+
# Operator overloading 1 : +
15+
def __add__(self, other):
16+
if not isinstance(other, Complex):
17+
other = Complex(other)
18+
return Complex(self.re + other.re, self.im + other.im)
19+
# Operator overloading 2 : -
20+
def __sub__(self, other):
21+
if not isinstance(other, Complex):
22+
other = Complex(other)
23+
return Complex(self.re - other.re, self.im - other.im)
24+
# Operator overloading 3 : *
25+
def __mul__(self, other):
26+
if not isinstance(other, Complex):
27+
other = Complex(other)
28+
return Complex(self.re * other.re - self.im * other.im, self.re * other.im + self.im * other.re)
29+
# Operator overloading 4 : /
30+
def __truediv__(self, other):
31+
try:
32+
if not isinstance(other, Complex):
33+
other = Complex(other)
34+
den = other * other.con()
35+
num = self * other.con()
36+
return Complex(num.re / den.re, num.im / den.re)
37+
except ZeroDivisionError as err:
38+
print('Error: {}'.format(err))
39+
# Operator overloading 5 : //
40+
def __floordiv__(self, other):
41+
try:
42+
if not isinstance(other, Complex):
43+
other = Complex(other)
44+
den = other * other.con()
45+
num = self * other.con()
46+
return Complex(num.re // den.re, num.im // den.re)
47+
except ZeroDivisionError as err:
48+
print('Error: {}'.format(err))
49+
def __gt__(self, other):
50+
if not isinstance(other, Complex):
51+
other = Complex(other)
52+
return self.mod() > other.mod()
53+
# Operator overloading 7 : >=
54+
def __ge__(self, other):
55+
if not isinstance(other, Complex):
56+
other = Complex(other)
57+
return self.mod() >= other.mod()
58+
# Operator overloading 8: <
59+
def __lt__(self, other):
60+
if not isinstance(other, Complex):
61+
other = Complex(other)
62+
return not self >= other
63+
# Operator overloading 9: <=
64+
def __le__(self, other):
65+
if not isinstance(other, Complex):
66+
other = Complex(other)
67+
return not self > other
68+
# Operator overloading 10: ==
69+
def __eq__(self, other):
70+
if not isinstance(other, Complex):
71+
other = Complex(other)
72+
return (self.re == other.re) and (self.im == other.im)
73+
# Operator overloading 11: !=
74+
def __ne__(self, other):
75+
if not isinstance(other, Complex):
76+
other = Complex(other)
77+
return not self == other
78+
# Operator overloading 12: +=
79+
def __iadd__(self, other):
80+
if not isinstance(other, Complex):
81+
other = Complex(other)
82+
self.re += other.re
83+
self.im += other.im
84+
return Complex(self.re, self.im)
85+
# Operator overloading 13: -=
86+
def __isub__(self, other):
87+
if not isinstance(other, Complex):
88+
other = Complex(other)
89+
self.re -= other.re
90+
self.im -= other.im
91+
return Complex(self.re, self.im)
92+
# Operator overloading 14: *=
93+
def __imul__(self, other):
94+
if not isinstance(other, Complex):
95+
other = Complex(other)
96+
self.re = self.re * other.re - self.im * other.im
97+
self.im = self.re * other.im + self.im * other.re
98+
return Complex(self.re, self.im)
99+
# Operator overloading 15: /=
100+
def __idiv__(self, other):
101+
try:
102+
if not isinstance(other, Complex):
103+
other = Complex(other)
104+
den = other * other.con()
105+
num = self * other.con()
106+
self.re = num.re / den.re
107+
self.im = num.im / den.re
108+
return Complex(self.re, self.im)
109+
except ZeroDivisionError as err:
110+
print('Error: {}'.format(err))
111+
# Operator overloading 16: //=
112+
def __ifloordiv__(self, other):
113+
try:
114+
if not isinstance(other, Complex):
115+
other = Complex(other)
116+
den = other * other.con()
117+
num = self * other.con()
118+
self.re = num.re // den.re
119+
self.im = num.im // den.re
120+
return Complex(self.re, self.im)
121+
except ZeroDivisionError as err:
122+
print('Error: {}'.format(err))
123+
## Helper functions
124+
# Module function to calculate the modulus of a complex number
125+
def mod(self):
126+
return sqrt(self.re**2 + self.im**2)
127+
# Conjugated of a complex number
128+
def con(self):
129+
return Complex(self.re, - self.im)
130+
# String function
131+
def __str__(self):
132+
output = str(self.re) + ' + ' + str(self.im) + 'j' if(self.im != 0) else str(self.re)
133+
output = str(self.re) + ' - ' + str(-self.im) + 'j' if (self.im < 0) else output
134+
return output

cmpx/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from . import Complex
2+
3+
__all__ = [
4+
'Complex'
5+
]

dist/cmpx-0.2-py3-none-any.whl

3.18 KB
Binary file not shown.

dist/cmpx-0.2.tar.gz

2 KB
Binary file not shown.

0 commit comments

Comments
 (0)