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
36f6e2c9
Kaydet (Commit)
36f6e2c9
authored
Eki 13, 2013
tarafından
Mark Dickinson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #18739: Fix inconsistent results from math.log(n) and math.log(long(n))
üst
65e30a2d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
12 deletions
+31
-12
test_math.py
Lib/test/test_math.py
+6
-0
NEWS
Misc/NEWS
+3
-0
mathmodule.c
Modules/mathmodule.c
+22
-12
No files found.
Lib/test/test_math.py
Dosyayı görüntüle @
36f6e2c9
...
...
@@ -599,6 +599,9 @@ class MathTests(unittest.TestCase):
self
.
assertEqual
(
math
.
log
(
INF
),
INF
)
self
.
assertRaises
(
ValueError
,
math
.
log
,
NINF
)
self
.
assertTrue
(
math
.
isnan
(
math
.
log
(
NAN
)))
# Log values should match for int and long (issue #18739).
for
n
in
range
(
1
,
1000
):
self
.
assertEqual
(
math
.
log
(
n
),
math
.
log
(
long
(
n
)))
def
testLog1p
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
log1p
)
...
...
@@ -621,6 +624,9 @@ class MathTests(unittest.TestCase):
self
.
assertEqual
(
math
.
log
(
INF
),
INF
)
self
.
assertRaises
(
ValueError
,
math
.
log10
,
NINF
)
self
.
assertTrue
(
math
.
isnan
(
math
.
log10
(
NAN
)))
# Log values should match for int and long (issue #18739).
for
n
in
range
(
1
,
1000
):
self
.
assertEqual
(
math
.
log10
(
n
),
math
.
log10
(
long
(
n
)))
def
testModf
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
modf
)
...
...
Misc/NEWS
Dosyayı görüntüle @
36f6e2c9
...
...
@@ -9,6 +9,9 @@ What's New in Python 2.7.6?
Core and Builtins
-----------------
- Issue #18739: Fix an inconsistency between math.log(n) and math.log(long(n));
the results could be off from one another by a ulp or two.
- Issue #13461: Fix a crash in the "replace" error handler on 64-bit platforms.
Patch by Yogesh Chaudhari.
...
...
Modules/mathmodule.c
Dosyayı görüntüle @
36f6e2c9
...
...
@@ -1277,23 +1277,33 @@ loghelper(PyObject* arg, double (*func)(double), char *funcname)
{
/* If it is long, do it ourselves. */
if
(
PyLong_Check
(
arg
))
{
double
x
;
double
x
,
result
;
Py_ssize_t
e
;
x
=
_PyLong_Frexp
((
PyLongObject
*
)
arg
,
&
e
);
if
(
x
==
-
1
.
0
&&
PyErr_Occurred
())
return
NULL
;
if
(
x
<=
0
.
0
)
{
/* Negative or zero inputs give a ValueError. */
if
(
Py_SIZE
(
arg
)
<=
0
)
{
PyErr_SetString
(
PyExc_ValueError
,
"math domain error"
);
return
NULL
;
}
/* Special case for log(1), to make sure we get an
exact result there. */
if
(
e
==
1
&&
x
==
0
.
5
)
return
PyFloat_FromDouble
(
0
.
0
);
/* Value is ~= x * 2**e, so the log ~= log(x) + log(2) * e. */
x
=
func
(
x
)
+
func
(
2
.
0
)
*
e
;
return
PyFloat_FromDouble
(
x
);
x
=
PyLong_AsDouble
(
arg
);
if
(
x
==
-
1
.
0
&&
PyErr_Occurred
())
{
if
(
!
PyErr_ExceptionMatches
(
PyExc_OverflowError
))
return
NULL
;
/* Here the conversion to double overflowed, but it's possible
to compute the log anyway. Clear the exception and continue. */
PyErr_Clear
();
x
=
_PyLong_Frexp
((
PyLongObject
*
)
arg
,
&
e
);
if
(
x
==
-
1
.
0
&&
PyErr_Occurred
())
return
NULL
;
/* Value is ~= x * 2**e, so the log ~= log(x) + log(2) * e. */
result
=
func
(
x
)
+
func
(
2
.
0
)
*
e
;
}
else
/* Successfully converted x to a double. */
result
=
func
(
x
);
return
PyFloat_FromDouble
(
result
);
}
/* Else let libm handle it by itself. */
...
...
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