Skip to content

rclcpp::Time and rclcpp::Duration max values not near max int64_t #1351

Open

Description

@Blast545

Follow up Issue to track the conversation in #1347 (comment)

Basically this is to consider a new approach to the one agreed on #538. The max method for Time and Duration IMO should return the max value of the representation in nanoseconds.

Not sure if that was a constrain in the past, but the sum / substraction operators can handle properly overflow and underflow operations, so I don't see any reason to limit the max value returned by the max method.

If this is not a desired approach, an update to the header of the function will be required, as it stated \return the maximum representable value which is not the case.

Tagging @clalancette for awareness

Activity

  1. added
    enhancement
    on Sep 29, 2020
  2. clalancette commented on Oct 15, 2020

    @clalancette
    Contributor

    @mabelzhang Make sure to read the linked issues and discussion, and talk to @Blast545 and @wjwwood about this one. My personal opinion is that we should make Time::max and Duration::max be the int32::max value for both seconds and nanoseconds; that just seems consistent.

  3. wjwwood commented on Nov 13, 2020

    @wjwwood
    Member

    I don't think the concern is about overflowing operations, I think the concern is that if you create a Time(std::numeric_limits<int32_t>::max(), 999999999) and then add a second, you will not overflow the time object (as the internal int64_t can store it and we don't artificially cap the value) but if you tried to convert it to the ROS message type, it would not fit as it uses int32 for the seconds field.

    Personally, I think limiting the value is odd, and I think changing the storage is a bad idea too, so I think we should change this max to return the max value we can represent, even if that wouldn't fit in the ROS message. That being said, it will not be possible to easily get the max value you can put in a message at that point. However, I'm not sure why you need that in the first place, or even why we need max functions for these classes in the first place, but perhaps there was a use case motivating it. The original issue #524 just states we need it, but it isn't clear why tests were doing it in the first place...

    The long term solution, imo, is to deprecate the existing time message and move towards one with a single int64_t, but that's gonna be hard to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backlogenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions