Skip to content

Allow Duration to be negative - #220

Merged
sloretz merged 2 commits into
masterfrom
negative_duration
Aug 10, 2018
Merged

sloretz merged 2 commits into
masterfrom
negative_duration

Conversation

@sloretz

@sloretz sloretz commented Aug 10, 2018

Copy link
Copy Markdown
Contributor

This allows Duration instances to be negative as talked about in ros2/rclcpp#525. Time is unchanged and cannot have negative values in this PR.

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@sloretz sloretz added the in review Waiting for review (Kanban column) label Aug 10, 2018
@sloretz sloretz self-assigned this Aug 10, 2018
Comment thread rclpy/test/test_time.py Outdated

with self.assertRaises(ValueError):
duration = Duration(seconds=-1)
duration = Duration(seconds=-1)

@dirk-thomas dirk-thomas Aug 10, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to assert the resulting duration.nanoseconds in this case. Maybe also try the lowest possible value and check that smaller values raise too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added check on resulting duration.nanoseconds plus a check on lowest possible value 7697213

The float seconds to integer nanoseconds precision isn't very good at that range. On my machine Duration(seconds=-2**63 / 1e9 - 954e-9) is the first negative floating point number to OverflowError, but I'm not sure how portable that is so I did -2**63 / 1e9 - 1 instead.

@dhood

dhood commented Aug 10, 2018

Copy link
Copy Markdown
Member

thanks for following up on this @sloretz. For context, this is a follow up to #209 (comment)

@sloretz

sloretz commented Aug 10, 2018

Copy link
Copy Markdown
Contributor Author

New CI

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@sloretz
sloretz merged commit 6fdb303 into master Aug 10, 2018
@sloretz
sloretz deleted the negative_duration branch August 10, 2018 18:35
@sloretz sloretz removed the in review Waiting for review (Kanban column) label Aug 10, 2018
YuanYuYuan pushed a commit to YuanYuYuan/rclpy that referenced this pull request Nov 12, 2025
Update roslibrust_serde_rosmsg to improve serialization speed
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.

3 participants