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
74135d0a
Kaydet (Commit)
74135d0a
authored
Tem 03, 2010
tarafından
Alexander Belopolsky
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Made minimal modifications to pass included tests
üst
418182e1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
17 deletions
+7
-17
Complex.py
Demo/classes/Complex.py
+7
-17
No files found.
Demo/classes/Complex.py
Dosyayı görüntüle @
74135d0a
...
...
@@ -151,13 +151,9 @@ class Complex:
raise
ValueError
(
"can't convert Complex with nonzero im to float"
)
return
float
(
self
.
re
)
def
__
cmp
__
(
self
,
other
):
def
__
eq
__
(
self
,
other
):
other
=
ToComplex
(
other
)
return
cmp
((
self
.
re
,
self
.
im
),
(
other
.
re
,
other
.
im
))
def
__rcmp__
(
self
,
other
):
other
=
ToComplex
(
other
)
return
cmp
(
other
,
self
)
return
(
self
.
re
,
self
.
im
)
==
(
other
.
re
,
other
.
im
)
def
__bool__
(
self
):
return
not
(
self
.
re
==
self
.
im
==
0
)
...
...
@@ -190,14 +186,14 @@ class Complex:
__rmul__
=
__mul__
def
__div__
(
self
,
other
):
def
__
true
div__
(
self
,
other
):
other
=
ToComplex
(
other
)
d
=
float
(
other
.
re
*
other
.
re
+
other
.
im
*
other
.
im
)
if
not
d
:
raise
ZeroDivisionError
(
'Complex division'
)
return
Complex
((
self
.
re
*
other
.
re
+
self
.
im
*
other
.
im
)
/
d
,
(
self
.
im
*
other
.
re
-
self
.
re
*
other
.
im
)
/
d
)
def
__rdiv__
(
self
,
other
):
def
__r
true
div__
(
self
,
other
):
other
=
ToComplex
(
other
)
return
other
/
self
...
...
@@ -226,8 +222,9 @@ def checkop(expr, a, b, value, fuzz = 1e-6):
print
(
' '
,
a
,
'and'
,
b
,
end
=
' '
)
try
:
result
=
eval
(
expr
)
except
:
result
=
sys
.
exc_info
()[
0
]
except
Exception
as
e
:
print
(
'!!
\t
!!
\t
!! error: {}'
.
format
(
e
))
return
print
(
'->'
,
result
)
if
isinstance
(
result
,
str
)
or
isinstance
(
value
,
str
):
ok
=
(
result
==
value
)
...
...
@@ -295,13 +292,6 @@ def test():
(
Complex
(
1
),
Complex
(
0
,
10
),
1
),
(
2
,
Complex
(
4
,
0
),
16
),
],
'cmp(a,b)'
:
[
(
1
,
10
,
-
1
),
(
1
,
Complex
(
0
,
10
),
1
),
(
Complex
(
0
,
10
),
1
,
-
1
),
(
Complex
(
0
,
10
),
Complex
(
1
),
-
1
),
(
Complex
(
1
),
Complex
(
0
,
10
),
1
),
],
}
for
expr
in
sorted
(
testsuite
):
print
(
expr
+
':'
)
...
...
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