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
9ae47dfb
Kaydet (Commit)
9ae47dfb
authored
Eyl 09, 2015
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
pytime: add _PyTime_Round() helper to factorize code
üst
ce6aa749
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
25 deletions
+20
-25
pytime.c
Python/pytime.c
+20
-25
No files found.
Python/pytime.c
Dosyayı görüntüle @
9ae47dfb
...
...
@@ -72,6 +72,17 @@ _PyTime_RoundHalfEven(double x)
return
rounded
;
}
static
double
_PyTime_Round
(
double
x
,
_PyTime_round_t
round
)
{
if
(
round
==
_PyTime_ROUND_HALF_EVEN
)
return
_PyTime_RoundHalfEven
(
x
);
else
if
(
round
==
_PyTime_ROUND_CEILING
)
return
ceil
(
x
);
else
return
floor
(
x
);
}
static
int
_PyTime_DoubleToDenominator
(
double
d
,
time_t
*
sec
,
long
*
numerator
,
double
denominator
,
_PyTime_round_t
round
)
...
...
@@ -83,12 +94,7 @@ _PyTime_DoubleToDenominator(double d, time_t *sec, long *numerator,
floatpart
=
modf
(
d
,
&
intpart
);
floatpart
*=
denominator
;
if
(
round
==
_PyTime_ROUND_HALF_EVEN
)
floatpart
=
_PyTime_RoundHalfEven
(
floatpart
);
else
if
(
round
==
_PyTime_ROUND_CEILING
)
floatpart
=
ceil
(
floatpart
);
else
floatpart
=
floor
(
floatpart
);
floatpart
=
_PyTime_Round
(
floatpart
,
round
);
if
(
floatpart
>=
denominator
)
{
floatpart
-=
denominator
;
intpart
+=
1
.
0
;
...
...
@@ -139,12 +145,7 @@ _PyTime_ObjectToTime_t(PyObject *obj, time_t *sec, _PyTime_round_t round)
volatile
double
d
;
d
=
PyFloat_AsDouble
(
obj
);
if
(
round
==
_PyTime_ROUND_HALF_EVEN
)
d
=
_PyTime_RoundHalfEven
(
d
);
else
if
(
round
==
_PyTime_ROUND_CEILING
)
d
=
ceil
(
d
);
else
d
=
floor
(
d
);
d
=
_PyTime_Round
(
d
,
round
);
(
void
)
modf
(
d
,
&
intpart
);
*
sec
=
(
time_t
)
intpart
;
...
...
@@ -255,7 +256,7 @@ _PyTime_FromTimeval(_PyTime_t *tp, struct timeval *tv, int raise)
static
int
_PyTime_FromFloatObject
(
_PyTime_t
*
t
,
double
value
,
_PyTime_round_t
round
,
long
to_nanosecond
s
)
long
unit_to_n
s
)
{
double
err
;
/* volatile avoids optimization changing how numbers are rounded */
...
...
@@ -263,14 +264,8 @@ _PyTime_FromFloatObject(_PyTime_t *t, double value, _PyTime_round_t round,
/* convert to a number of nanoseconds */
d
=
value
;
d
*=
to_nanoseconds
;
if
(
round
==
_PyTime_ROUND_HALF_EVEN
)
d
=
_PyTime_RoundHalfEven
(
d
);
else
if
(
round
==
_PyTime_ROUND_CEILING
)
d
=
ceil
(
d
);
else
d
=
floor
(
d
);
d
*=
(
double
)
unit_to_ns
;
d
=
_PyTime_Round
(
d
,
round
);
*
t
=
(
_PyTime_t
)
d
;
err
=
d
-
(
double
)
*
t
;
...
...
@@ -283,12 +278,12 @@ _PyTime_FromFloatObject(_PyTime_t *t, double value, _PyTime_round_t round,
static
int
_PyTime_FromObject
(
_PyTime_t
*
t
,
PyObject
*
obj
,
_PyTime_round_t
round
,
long
to_nanosecond
s
)
long
unit_to_n
s
)
{
if
(
PyFloat_Check
(
obj
))
{
double
d
;
d
=
PyFloat_AsDouble
(
obj
);
return
_PyTime_FromFloatObject
(
t
,
d
,
round
,
to_nanosecond
s
);
return
_PyTime_FromFloatObject
(
t
,
d
,
round
,
unit_to_n
s
);
}
else
{
#ifdef HAVE_LONG_LONG
...
...
@@ -305,8 +300,8 @@ _PyTime_FromObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t round,
_PyTime_overflow
();
return
-
1
;
}
*
t
=
sec
*
to_nanosecond
s
;
if
(
*
t
/
to_nanosecond
s
!=
sec
)
{
*
t
=
sec
*
unit_to_n
s
;
if
(
*
t
/
unit_to_n
s
!=
sec
)
{
_PyTime_overflow
();
return
-
1
;
}
...
...
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