@@ -9,37 +9,38 @@ abstract TVal
9
9
type Time <: TVal
10
10
secs:: Int32
11
11
nsecs:: Int32
12
- Time (s,n) = begin
12
+ function Time (s:: Real ,n :: Real )
13
13
cs, cns = _canonical_time (s,n)
14
14
new (cs, cns)
15
15
end
16
16
end
17
17
Time () = Time (0 ,0 )
18
- Time (t:: FloatingPoint ) =
19
- Time (floor (Int32, t), round (Int32, mod (t,1 )* 1e9 ))
18
+ Time (t:: Real ) = Time (t,0 )
20
19
21
20
type Duration <: TVal
22
21
secs:: Int32
23
22
nsecs:: Int32
24
- Duration (s,n) = begin
23
+ function Duration (s:: Real ,n :: Real )
25
24
cs, cns = _canonical_time (s,n)
26
25
new (cs, cns)
27
26
end
28
27
end
29
28
Duration () = Duration (0 ,0 )
30
- Duration (t:: FloatingPoint ) =
31
- Duration (floor (Int32,t), round (Int32, mod (t,1 )* 1e9 ))
29
+ Duration (t:: Real ) = Duration (t,0 )
32
30
33
31
# Enforce 0 <= nsecs < 1e9
34
- function _canonical_time (secs:: Integer , nsecs:: Integer )
35
- nsec_conv = int32 (1_000_000_000 )
36
- dsecs = convert (Int32, div (nsecs, nsec_conv))
37
- rnsecs = convert (Int32, rem (nsecs, nsec_conv))
38
- if rnsecs < 0
39
- dsecs = dsecs - one (Int32)
40
- rnsecs = rnsecs + nsec_conv
32
+ function _canonical_time (secs, nsecs)
33
+ nsec_conv = convert (Int32, 1_000_000_000 )
34
+ secs32 = floor (Int32, secs)
35
+ nsecs32 = floor (Int32, mod (secs,1 )* 1e9 + nsecs)
36
+
37
+ addsecs = div (nsecs32, nsec_conv)
38
+ crnsecs = rem (nsecs32, nsec_conv)
39
+ if crnsecs < 0
40
+ addsecs -= one (Int32)
41
+ crnsecs += nsec_conv
41
42
end
42
- (secs + dsecs, rnsecs )
43
+ (secs32 + addsecs, crnsecs )
43
44
end
44
45
45
46
# Temporal arithmetic
@@ -57,7 +58,7 @@ convert(::Type{PyObject}, t::Time) = __rospy__.Time (t.secs,t.nsecs)
57
58
convert (:: Type{PyObject} , t:: Duration ) = __rospy__. Duration (t. secs,t. nsecs)
58
59
59
60
# Real number conversions
60
- to_sec {T<:TVal} (t:: T ) = float64 ( t. secs) + 1e-9 * float64 ( t. nsecs)
61
+ to_sec {T<:TVal} (t:: T ) = t. secs + 1e-9 * t. nsecs
61
62
to_nsec {T<:TVal} (t:: T ) = 1_000_000_000 * t. secs + t. nsecs
62
63
convert {T<:TVal} (:: Type{Float64} , t:: T ) = to_sec (t)
63
64
@@ -72,7 +73,7 @@ isless{T<:TVal}(t1::T, t2::T) = to_nsec(t1) < to_nsec(t2)
72
73
type Rate
73
74
o:: PyObject
74
75
end
75
- Rate (hz:: FloatingPoint ) = Rate (__rospy__. Rate (hz))
76
+ Rate (hz:: Real ) = Rate (__rospy__. Rate (hz))
76
77
Rate (d:: Duration ) = Rate (1.0 / to_sec (d))
77
78
78
79
type Timer
0 commit comments