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
e7214a13
Kaydet (Commit)
e7214a13
authored
Ara 18, 2005
tarafından
Neal Norwitz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Get float() to be more portable across platforms. Disable hex strings.
üst
87b801cc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
50 deletions
+32
-50
test_builtin.py
Lib/test/test_builtin.py
+4
-2
NEWS
Misc/NEWS
+3
-0
pystrtod.c
Python/pystrtod.c
+25
-48
No files found.
Lib/test/test_builtin.py
Dosyayı görüntüle @
e7214a13
...
...
@@ -545,6 +545,8 @@ class BuiltinTest(unittest.TestCase):
self
.
assertEqual
(
float
(
314
),
314.0
)
self
.
assertEqual
(
float
(
314L
),
314.0
)
self
.
assertEqual
(
float
(
" 3.14 "
),
3.14
)
self
.
assertRaises
(
ValueError
,
float
,
" 0x3.1 "
)
self
.
assertRaises
(
ValueError
,
float
,
" -0x3.p-1 "
)
if
have_unicode
:
self
.
assertEqual
(
float
(
unicode
(
" 3.14 "
)),
3.14
)
self
.
assertEqual
(
float
(
unicode
(
"
\u0663
.
\u0661\u0664
"
,
'raw-unicode-escape'
)),
3.14
)
...
...
@@ -572,8 +574,8 @@ class BuiltinTest(unittest.TestCase):
self
.
assertEqual
(
float
(
" 3,14 "
),
3.14
)
self
.
assertEqual
(
float
(
" +3,14 "
),
3.14
)
self
.
assertEqual
(
float
(
" -3,14 "
),
-
3.14
)
self
.
assert
Equal
(
float
(
" 0x3.1 "
),
3.0625
)
self
.
assert
Equal
(
float
(
" -0x3.p-1 "
),
-
1.5
)
self
.
assert
Raises
(
ValueError
,
float
,
" 0x3.1 "
)
self
.
assert
Raises
(
ValueError
,
float
,
" -0x3.p-1 "
)
self
.
assertEqual
(
float
(
" 25.e-1 "
),
2.5
)
self
.
assertEqual
(
fcmp
(
float
(
" .25e-1 "
),
.
025
),
0
)
finally
:
...
...
Misc/NEWS
Dosyayı görüntüle @
e7214a13
...
...
@@ -12,6 +12,9 @@ What's New in Python 2.5 alpha 1?
Core and builtins
-----------------
- Support for converting hex strings to floats no longer works.
This was not portable. float('
0x3
') now raises a ValueError.
- Patch #1382163: Expose Subversion revision number to Python. New C API
function Py_GetBuildNumber(). New attribute sys.build_number. Build number
is now displayed in interactive prompt banner.
...
...
Python/pystrtod.c
Dosyayı görüntüle @
e7214a13
...
...
@@ -38,8 +38,7 @@
* Return value: the #gdouble value.
**/
double
PyOS_ascii_strtod
(
const
char
*
nptr
,
char
**
endptr
)
PyOS_ascii_strtod
(
const
char
*
nptr
,
char
**
endptr
)
{
char
*
fail_pos
;
double
val
;
...
...
@@ -49,7 +48,6 @@ PyOS_ascii_strtod(const char *nptr,
const
char
*
p
,
*
decimal_point_pos
;
const
char
*
end
=
NULL
;
/* Silence gcc */
/* g_return_val_if_fail (nptr != NULL, 0); */
assert
(
nptr
!=
NULL
);
fail_pos
=
NULL
;
...
...
@@ -73,64 +71,36 @@ PyOS_ascii_strtod(const char *nptr,
if
(
*
p
==
'+'
||
*
p
==
'-'
)
p
++
;
if
(
p
[
0
]
==
'0'
&&
(
p
[
1
]
==
'x'
||
p
[
1
]
==
'X'
))
while
(
ISDIGIT
(
*
p
))
p
++
;
if
(
*
p
==
'.'
)
{
p
+=
2
;
/* HEX - find the (optional) decimal point */
decimal_point_pos
=
p
++
;
while
(
IS
X
DIGIT
(
*
p
))
while
(
ISDIGIT
(
*
p
))
p
++
;
if
(
*
p
==
'.'
)
{
decimal_point_pos
=
p
++
;
while
(
ISXDIGIT
(
*
p
))
p
++
;
if
(
*
p
==
'p'
||
*
p
==
'P'
)
p
++
;
if
(
*
p
==
'+'
||
*
p
==
'-'
)
p
++
;
while
(
ISDIGIT
(
*
p
))
p
++
;
end
=
p
;
}
}
else
{
if
(
*
p
==
'e'
||
*
p
==
'E'
)
p
++
;
if
(
*
p
==
'+'
||
*
p
==
'-'
)
p
++
;
while
(
ISDIGIT
(
*
p
))
p
++
;
if
(
*
p
==
'.'
)
{
decimal_point_pos
=
p
++
;
while
(
ISDIGIT
(
*
p
))
p
++
;
if
(
*
p
==
'e'
||
*
p
==
'E'
)
p
++
;
if
(
*
p
==
'+'
||
*
p
==
'-'
)
p
++
;
while
(
ISDIGIT
(
*
p
))
p
++
;
end
=
p
;
}
end
=
p
;
}
/* For the other cases, we need not convert the decimal point */
/* For the other cases, we need not convert the decimal point */
}
/* Set errno to zero, so that we can distinguish zero results
and underflows */
/* Set errno to zero, so that we can distinguish zero results
and underflows */
errno
=
0
;
if
(
decimal_point_pos
)
{
char
*
copy
,
*
c
;
/* We need to convert the '.' to the locale specific decimal point */
/* We need to convert the '.' to the locale specific decimal point */
copy
=
malloc
(
end
-
nptr
+
1
+
decimal_point_len
);
c
=
copy
;
...
...
@@ -155,8 +125,15 @@ PyOS_ascii_strtod(const char *nptr,
free
(
copy
);
}
else
val
=
strtod
(
nptr
,
&
fail_pos
);
else
{
unsigned
i
=
0
;
if
(
nptr
[
i
]
==
'-'
)
i
++
;
if
(
nptr
[
i
]
==
'0'
&&
(
nptr
[
i
+
1
]
==
'x'
||
nptr
[
i
+
1
]
==
'X'
))
fail_pos
=
nptr
;
else
val
=
strtod
(
nptr
,
&
fail_pos
);
}
if
(
endptr
)
*
endptr
=
fail_pos
;
...
...
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