Skip to content

Commit

Permalink
try using llround
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminp committed Oct 3, 2022
1 parent b0f89cb commit be7bea9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Python/pytime.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# include <winsock2.h> // struct timeval
#endif

#include <fenv.h>

#if defined(__APPLE__)
# include <mach/mach_time.h> // mach_absolute_time(), mach_timebase_info()

Expand Down Expand Up @@ -515,11 +517,12 @@ pytime_from_double(_PyTime_t *tp, double value, _PyTime_round_t round,
d *= (double)unit_to_ns;
d = pytime_round(d, round);

if (!_Py_InIntegralTypeRange(_PyTime_t, d)) {
feclearexcept(FE_ALL_EXCEPT);
_PyTime_t ns = llround(d);
if (fetestexcept(FE_INVALID)) {
pytime_overflow();
return -1;
}
_PyTime_t ns = (_PyTime_t)d;

*tp = pytime_from_nanoseconds(ns);
return 0;
Expand Down

0 comments on commit be7bea9

Please sign in to comment.