Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
72ba6160
Kaydet (Commit)
72ba6160
authored
Tem 30, 1996
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added note about Python's support of complex numbers.
Added exp(z).
üst
89cb67bb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
1 deletion
+11
-1
Complex.py
Demo/classes/Complex.py
+11
-1
No files found.
Demo/classes/Complex.py
Dosyayı görüntüle @
72ba6160
# Complex numbers
# Complex numbers
# ---------------
# ---------------
# [Now that Python has a complex data type built-in, this is not very
# useful, but it's still a nice example class]
# This module represents complex numbers as instances of the class Complex.
# This module represents complex numbers as instances of the class Complex.
# A Complex instance z has two data attribues, z.re (the real part) and z.im
# A Complex instance z has two data attribues, z.re (the real part) and z.im
# (the imaginary part). In fact, z.re and z.im can have any value -- all
# (the imaginary part). In fact, z.re and z.im can have any value -- all
...
@@ -15,6 +18,7 @@
...
@@ -15,6 +18,7 @@
# PolarToComplex([r [,phi [,fullcircle]]]) ->
# PolarToComplex([r [,phi [,fullcircle]]]) ->
# the complex number z for which r == z.radius() and phi == z.angle(fullcircle)
# the complex number z for which r == z.radius() and phi == z.angle(fullcircle)
# (r and phi default to 0)
# (r and phi default to 0)
# exp(z) -> returns the complex exponential of z. Equivalent to pow(math.e,z).
#
#
# Complex numbers have the following methods:
# Complex numbers have the following methods:
# z.abs() -> absolute value of z
# z.abs() -> absolute value of z
...
@@ -202,7 +206,9 @@ class Complex:
...
@@ -202,7 +206,9 @@ class Complex:
if
z
is
not
None
:
if
z
is
not
None
:
raise
TypeError
,
'Complex does not support ternary pow()'
raise
TypeError
,
'Complex does not support ternary pow()'
if
IsComplex
(
n
):
if
IsComplex
(
n
):
if
n
.
im
:
raise
TypeError
,
'Complex to the Complex power'
if
n
.
im
:
if
self
.
im
:
raise
TypeError
,
'Complex to the Complex power'
else
:
return
exp
(
math
.
log
(
self
.
re
)
*
n
)
n
=
n
.
re
n
=
n
.
re
r
=
pow
(
self
.
abs
(),
n
)
r
=
pow
(
self
.
abs
(),
n
)
phi
=
n
*
self
.
angle
()
phi
=
n
*
self
.
angle
()
...
@@ -211,6 +217,10 @@ class Complex:
...
@@ -211,6 +217,10 @@ class Complex:
def
__rpow__
(
self
,
base
):
def
__rpow__
(
self
,
base
):
base
=
ToComplex
(
base
)
base
=
ToComplex
(
base
)
return
pow
(
base
,
self
)
return
pow
(
base
,
self
)
def
exp
(
z
):
r
=
math
.
exp
(
z
.
re
)
return
Complex
(
math
.
cos
(
z
.
im
)
*
r
,
math
.
sin
(
z
.
im
)
*
r
)
def
checkop
(
expr
,
a
,
b
,
value
,
fuzz
=
1e-6
):
def
checkop
(
expr
,
a
,
b
,
value
,
fuzz
=
1e-6
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment