mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
test_time: rewrite PyTime API rounding tests
Drop all hardcoded tests. Instead, reimplement each function in Python, usually using decimal.Decimal for the rounding mode. Add much more values to the dataset. Test various timestamp units from picroseconds to seconds, in integer and float. Enhance also _PyTime_AsSecondsDouble().
This commit is contained in:
parent
9ae47dfbd9
commit
3e2c8d84c6
2 changed files with 221 additions and 545 deletions
|
@ -324,12 +324,16 @@ _PyTime_FromMillisecondsObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t roun
|
|||
double
|
||||
_PyTime_AsSecondsDouble(_PyTime_t t)
|
||||
{
|
||||
_PyTime_t sec, ns;
|
||||
/* Divide using integers to avoid rounding issues on the integer part.
|
||||
1e-9 cannot be stored exactly in IEEE 64-bit. */
|
||||
sec = t / SEC_TO_NS;
|
||||
ns = t % SEC_TO_NS;
|
||||
return (double)sec + (double)ns * 1e-9;
|
||||
if (t % SEC_TO_NS == 0) {
|
||||
_PyTime_t secs;
|
||||
/* Divide using integers to avoid rounding issues on the integer part.
|
||||
1e-9 cannot be stored exactly in IEEE 64-bit. */
|
||||
secs = t / SEC_TO_NS;
|
||||
return (double)secs;
|
||||
}
|
||||
else {
|
||||
return (double)t / 1e9;
|
||||
}
|
||||
}
|
||||
|
||||
PyObject *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue