@@ -2494,20 +2494,19 @@ cdef class _Timedelta(timedelta):
2494
2494
"""
2495
2495
compute the components
2496
2496
"""
2497
- cdef int64_t sfrac, ifrac, ivalue = self .value
2498
- cdef float64_t frac
2497
+ cdef int64_t sfrac, ifrac, frac, ivalue = self .value
2499
2498
2500
2499
if self .is_populated:
2501
2500
return
2502
2501
2503
2502
# put frac in seconds
2504
- frac = float ( ivalue) / 1e9
2503
+ frac = ivalue/ ( 1000 * 1000 * 1000 )
2505
2504
if frac < 0 :
2506
2505
self ._sign = - 1
2507
2506
2508
2507
# 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
2511
2510
frac += 86400 * self ._d
2512
2511
else :
2513
2512
frac = - frac
@@ -2516,39 +2515,37 @@ cdef class _Timedelta(timedelta):
2516
2515
self ._d = 0
2517
2516
2518
2517
if frac >= 86400 :
2519
- self ._d += int ( frac / 86400 )
2518
+ self ._d += frac / 86400
2520
2519
frac -= self ._d * 86400
2521
2520
2522
2521
if frac >= 3600 :
2523
- self ._h = int ( frac / 3600 )
2522
+ self ._h = frac / 3600
2524
2523
frac -= self ._h * 3600
2525
2524
else :
2526
2525
self ._h = 0
2527
2526
2528
2527
if frac >= 60 :
2529
- self ._m = int ( frac / 60 )
2528
+ self ._m = frac / 60
2530
2529
frac -= self ._m * 60
2531
2530
else :
2532
2531
self ._m = 0
2533
2532
2534
2533
if frac >= 0 :
2535
- self ._s = int ( frac)
2534
+ self ._s = frac
2536
2535
frac -= self ._s
2537
2536
else :
2538
2537
self ._s = 0
2539
2538
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)
2548
2544
2549
- self ._ms = int (ifrac/ 1e6 )
2545
+ if ifrac != 0 :
2546
+ self ._ms = ifrac/ (1000 * 1000 )
2550
2547
ifrac -= self ._ms* 1000 * 1000
2551
- self ._us = int ( ifrac/ 1e3 )
2548
+ self ._us = ifrac/ 1000
2552
2549
ifrac -= self ._us* 1000
2553
2550
self ._ns = ifrac
2554
2551
else :
0 commit comments