@@ -2494,20 +2494,19 @@ cdef class _Timedelta(timedelta):
24942494 """
24952495 compute the components
24962496 """
2497- cdef int64_t sfrac, ifrac, ivalue = self .value
2498- cdef float64_t frac
2497+ cdef int64_t sfrac, ifrac, frac, ivalue = self .value
24992498
25002499 if self .is_populated:
25012500 return
25022501
25032502 # put frac in seconds
2504- frac = float ( ivalue) / 1e9
2503+ frac = ivalue/ ( 1000 * 1000 * 1000 )
25052504 if frac < 0 :
25062505 self ._sign = - 1
25072506
25082507 # even fraction
2509- if int (- frac/ 86400 ) != - frac / 86400. 0 :
2510- self ._d = int ( - frac/ 86400.0 + 1 )
2508+ if (- frac % 86400 ) != 0 :
2509+ self ._d = - frac/ 86400 + 1
25112510 frac += 86400 * self ._d
25122511 else :
25132512 frac = - frac
@@ -2516,39 +2515,37 @@ cdef class _Timedelta(timedelta):
25162515 self ._d = 0
25172516
25182517 if frac >= 86400 :
2519- self ._d += int ( frac / 86400 )
2518+ self ._d += frac / 86400
25202519 frac -= self ._d * 86400
25212520
25222521 if frac >= 3600 :
2523- self ._h = int ( frac / 3600 )
2522+ self ._h = frac / 3600
25242523 frac -= self ._h * 3600
25252524 else :
25262525 self ._h = 0
25272526
25282527 if frac >= 60 :
2529- self ._m = int ( frac / 60 )
2528+ self ._m = frac / 60
25302529 frac -= self ._m * 60
25312530 else :
25322531 self ._m = 0
25332532
25342533 if frac >= 0 :
2535- self ._s = int ( frac)
2534+ self ._s = frac
25362535 frac -= self ._s
25372536 else :
25382537 self ._s = 0
25392538
2540- if frac != 0 :
2541-
2542- # reset so we don't lose precision
2543- sfrac = int ((self ._h* 3600 + self ._m* 60 + self ._s)* 1e9 )
2544- if self ._sign < 0 :
2545- ifrac = ivalue + self ._d* DAY_NS - sfrac
2546- else :
2547- ifrac = ivalue - (self ._d* DAY_NS + sfrac)
2539+ sfrac = (self ._h* 3600 + self ._m* 60 + self ._s)* (1000 * 1000 * 1000 )
2540+ if self ._sign < 0 :
2541+ ifrac = ivalue + self ._d* DAY_NS - sfrac
2542+ else :
2543+ ifrac = ivalue - (self ._d* DAY_NS + sfrac)
25482544
2549- self ._ms = int (ifrac/ 1e6 )
2545+ if ifrac != 0 :
2546+ self ._ms = ifrac/ (1000 * 1000 )
25502547 ifrac -= self ._ms* 1000 * 1000
2551- self ._us = int ( ifrac/ 1e3 )
2548+ self ._us = ifrac/ 1000
25522549 ifrac -= self ._us* 1000
25532550 self ._ns = ifrac
25542551 else :
0 commit comments