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
0df5a858
Kaydet (Commit)
0df5a858
authored
Tem 02, 2010
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
üst
f5e81d62
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
42 deletions
+49
-42
test_float.py
Lib/test/test_float.py
+49
-42
No files found.
Lib/test/test_float.py
Dosyayı görüntüle @
0df5a858
...
...
@@ -12,8 +12,13 @@ import sys
INF
=
float
(
"inf"
)
NAN
=
float
(
"nan"
)
have_getformat
=
hasattr
(
float
,
"__getformat__"
)
requires_getformat
=
unittest
.
skipUnless
(
have_getformat
,
"requires __getformat__"
)
requires_setformat
=
unittest
.
skipUnless
(
hasattr
(
float
,
"__setformat__"
),
"requires __setformat__"
)
# decorator for skipping tests on non-IEEE 754 platforms
requires_IEEE_754
=
unittest
.
skipUnless
(
requires_IEEE_754
=
unittest
.
skipUnless
(
have_getformat
and
float
.
__getformat__
(
"double"
)
.
startswith
(
"IEEE"
),
"test requires IEEE 754 doubles"
)
...
...
@@ -357,6 +362,7 @@ class GeneralFloatCases(unittest.TestCase):
#self.assertTrue(0.0 > pow_op(-2.0, -1047) > -1e-315)
@requires_setformat
class
FormatFunctionsTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
@@ -407,6 +413,7 @@ LE_FLOAT_NAN = ''.join(reversed(BE_FLOAT_NAN))
# on non-IEEE platforms, attempting to unpack a bit pattern
# representing an infinity or a NaN should raise an exception.
@requires_setformat
class
UnknownFormatTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
save_formats
=
{
'double'
:
float
.
__getformat__
(
'double'
),
...
...
@@ -439,41 +446,42 @@ class UnknownFormatTestCase(unittest.TestCase):
# let's also try to guarantee that -0.0 and 0.0 don't get confused.
class
IEEEFormatTestCase
(
unittest
.
TestCase
):
if
float
.
__getformat__
(
"double"
)
.
startswith
(
"IEEE"
):
def
test_double_specials_do_unpack
(
self
):
for
fmt
,
data
in
[(
'>d'
,
BE_DOUBLE_INF
),
(
'>d'
,
BE_DOUBLE_NAN
),
(
'<d'
,
LE_DOUBLE_INF
),
(
'<d'
,
LE_DOUBLE_NAN
)]:
struct
.
unpack
(
fmt
,
data
)
if
float
.
__getformat__
(
"float"
)
.
startswith
(
"IEEE"
):
def
test_float_specials_do_unpack
(
self
):
for
fmt
,
data
in
[(
'>f'
,
BE_FLOAT_INF
),
(
'>f'
,
BE_FLOAT_NAN
),
(
'<f'
,
LE_FLOAT_INF
),
(
'<f'
,
LE_FLOAT_NAN
)]:
struct
.
unpack
(
fmt
,
data
)
if
float
.
__getformat__
(
"double"
)
.
startswith
(
"IEEE"
):
def
test_negative_zero
(
self
):
def
pos_pos
():
return
0.0
,
math
.
atan2
(
0.0
,
-
1
)
def
pos_neg
():
return
0.0
,
math
.
atan2
(
-
0.0
,
-
1
)
def
neg_pos
():
return
-
0.0
,
math
.
atan2
(
0.0
,
-
1
)
def
neg_neg
():
return
-
0.0
,
math
.
atan2
(
-
0.0
,
-
1
)
self
.
assertEquals
(
pos_pos
(),
neg_pos
())
self
.
assertEquals
(
pos_neg
(),
neg_neg
())
if
float
.
__getformat__
(
"double"
)
.
startswith
(
"IEEE"
):
def
test_underflow_sign
(
self
):
# check that -1e-1000 gives -0.0, not 0.0
self
.
assertEquals
(
math
.
atan2
(
-
1e-1000
,
-
1
),
math
.
atan2
(
-
0.0
,
-
1
))
self
.
assertEquals
(
math
.
atan2
(
float
(
'-1e-1000'
),
-
1
),
math
.
atan2
(
-
0.0
,
-
1
))
@requires_IEEE_754
def
test_double_specials_do_unpack
(
self
):
for
fmt
,
data
in
[(
'>d'
,
BE_DOUBLE_INF
),
(
'>d'
,
BE_DOUBLE_NAN
),
(
'<d'
,
LE_DOUBLE_INF
),
(
'<d'
,
LE_DOUBLE_NAN
)]:
struct
.
unpack
(
fmt
,
data
)
@requires_IEEE_754
def
test_float_specials_do_unpack
(
self
):
for
fmt
,
data
in
[(
'>f'
,
BE_FLOAT_INF
),
(
'>f'
,
BE_FLOAT_NAN
),
(
'<f'
,
LE_FLOAT_INF
),
(
'<f'
,
LE_FLOAT_NAN
)]:
struct
.
unpack
(
fmt
,
data
)
@requires_IEEE_754
def
test_negative_zero
(
self
):
def
pos_pos
():
return
0.0
,
math
.
atan2
(
0.0
,
-
1
)
def
pos_neg
():
return
0.0
,
math
.
atan2
(
-
0.0
,
-
1
)
def
neg_pos
():
return
-
0.0
,
math
.
atan2
(
0.0
,
-
1
)
def
neg_neg
():
return
-
0.0
,
math
.
atan2
(
-
0.0
,
-
1
)
self
.
assertEquals
(
pos_pos
(),
neg_pos
())
self
.
assertEquals
(
pos_neg
(),
neg_neg
())
@requires_IEEE_754
def
test_underflow_sign
(
self
):
# check that -1e-1000 gives -0.0, not 0.0
self
.
assertEquals
(
math
.
atan2
(
-
1e-1000
,
-
1
),
math
.
atan2
(
-
0.0
,
-
1
))
self
.
assertEquals
(
math
.
atan2
(
float
(
'-1e-1000'
),
-
1
),
math
.
atan2
(
-
0.0
,
-
1
))
def
test_format
(
self
):
# these should be rewritten to use both format(x, spec) and
...
...
@@ -530,8 +538,7 @@ class IEEEFormatTestCase(unittest.TestCase):
self
.
assertEqual
(
'{0:f}'
.
format
(
NAN
),
'nan'
)
self
.
assertEqual
(
'{0:F}'
.
format
(
NAN
),
'NAN'
)
@unittest.skipUnless
(
float
.
__getformat__
(
"double"
)
.
startswith
(
"IEEE"
),
"test requires IEEE 754 doubles"
)
@requires_IEEE_754
def
test_format_testfile
(
self
):
for
line
in
open
(
format_testfile
):
if
line
.
startswith
(
'--'
):
...
...
@@ -613,8 +620,8 @@ class ReprTestCase(unittest.TestCase):
self
.
assertEqual
(
s
,
repr
(
float
(
s
)))
self
.
assertEqual
(
negs
,
repr
(
float
(
negs
)))
@unittest.skipUnless
(
float
.
__getformat__
(
"double"
)
.
startswith
(
"IEEE"
),
"test requires IEEE 754 doubles"
)
@requires_IEEE_754
class
RoundTestCase
(
unittest
.
TestCase
):
def
test_second_argument_type
(
self
):
# any type with an __index__ method should be permitted as
...
...
@@ -752,8 +759,8 @@ class RoundTestCase(unittest.TestCase):
self
.
assertAlmostEqual
(
round
(
0.5e22
,
-
22
),
1e22
)
self
.
assertAlmostEqual
(
round
(
1.5e22
,
-
22
),
2e22
)
@unittest.skipUnless
(
float
.
__getformat__
(
"double"
)
.
startswith
(
"IEEE"
),
"test requires IEEE 754 doubles"
)
@requires_IEEE_754
def
test_format_specials
(
self
):
# Test formatting of nans and infs.
...
...
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