Skip to content

Allow nanosec < 0#38

Closed
sloretz wants to merge 1 commit intomasterfrom
negative_duration
Closed

Allow nanosec < 0#38
sloretz wants to merge 1 commit intomasterfrom
negative_duration

Conversation

@sloretz
Copy link
Copy Markdown
Contributor

@sloretz sloretz commented Jul 27, 2018

While fixing an issue found in ros2/rclcpp#525 I noticed the nanosec is unsigned. I'm not sure what this is supposed to mean. Does nanosec always have the same sign as sec, or is it always positive?

Code in rclcpp just adds the two together. However, ros2/rcutils#79 was opened to prevent mixing of signed/unsigned types. This PR makes nanosec signed, and adds a comment saying the two fields are to be combined by addition.

CI on ros2/rclcpp#527

@sloretz sloretz added the in review Waiting for review (Kanban column) label Jul 27, 2018
@sloretz sloretz self-assigned this Jul 27, 2018
@dirk-thomas
Copy link
Copy Markdown
Member

I think this will diverge from how DDS specifies duration_t. We should carefully consider the consequences,

@dirk-thomas
Copy link
Copy Markdown
Member

Imo it would be even better to keep it as unsigned and once .idl will allow us to specify that also constrain the upper limit to < 1 000 000 000.

@wjwwood
Copy link
Copy Markdown
Member

wjwwood commented Jul 27, 2018

Changing it to signed isn't a good idea imo. You can't really compare it to the rcl time point duration because it's a single nanoseconds value, not part of a nanoseconds/seconds pair.

If we were to change this at all I'd advocate for a single nanoseconds signed 64-bit integer, but that would probably be too disruptive (different argument and out of scope for this issue at least).

I don't think we should compare to how DDS does it, since they're probably going to change their seconds component to unsigned to avoid the 2038 problem. They won't change anything for 2038 with respect to durations, only time points.

Either way I wouldn't make the change proposed here.

@wjwwood
Copy link
Copy Markdown
Member

wjwwood commented Jul 27, 2018

Err, I thought we were talking about a time point not a duration, so never mind the part about 2038 problem.

I still would leave this with an unsigned nanoseconds, though I could possibly be swayed if we could enforce the boundary on it that it's within [0, 1e9).

@dirk-thomas
Copy link
Copy Markdown
Member

I think the comparison to DDS is valuable. Not necessarily as in "follow what they do" but "consider why they chose what they did. The upper bound ensures that a duration message is automatically "nomalized" which I think is a good thing.

@wjwwood
Copy link
Copy Markdown
Member

wjwwood commented Jul 27, 2018

The upper bound ensures that a duration message is automatically "nomalized" which I think is a good thing.

Well, signed or unsigned doesn't change the boundary issue. It just means you need two boundaries or just one. Whereas having signed nanoseconds avoids mixing unsigned and signed arithmetic.

@tfoote
Copy link
Copy Markdown
Contributor

tfoote commented Jul 27, 2018

The other thing to consider for consistency is the same semantic as ROS1. If we're going to break that consistency there's not much reason to keep it in two fields. The 64bit signed nanoseconds is much simpler to process. But for now I'd suggest keeping it as is.

@sloretz
Copy link
Copy Markdown
Contributor Author

sloretz commented Jul 27, 2018

Ignoring the signed/unsigned mixing for the moment, if the duration message is signed sec and unsigned nanosec, then what is the length of time indicated by .sec = -1, .nanosec=500000000?

@dirk-thomas
Copy link
Copy Markdown
Member

what is the length of time indicated by .sec = -1, .nanosec=500000000

- 500 000 000 ns

@sloretz
Copy link
Copy Markdown
Contributor Author

sloretz commented Aug 1, 2018

Thanks for the explanation.

@sloretz sloretz closed this Aug 1, 2018
@sloretz sloretz deleted the negative_duration branch August 1, 2018 19:07
@sloretz sloretz removed the in review Waiting for review (Kanban column) label Aug 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants