-
Notifications
You must be signed in to change notification settings - Fork 121
Creating More Accuracy in NS_TO_S #460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: rolling
Are you sure you want to change the base?
Changes from 3 commits
196e3bf
375e2f2
431e7f6
627a2ea
006e414
4f51c49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,10 @@ extern "C" | |
| #define RCUTILS_US_TO_NS(microseconds) ((microseconds) * 1000LL) | ||
|
|
||
| /// Convenience macro to convert nanoseconds to seconds. | ||
| #define RCUTILS_NS_TO_S(nanoseconds) ((nanoseconds) / (1000LL * 1000LL * 1000LL)) | ||
| #define RCUTILS_NS_TO_S(nanoseconds) \ | ||
| ((1e-9 * (double)((int32_t)(nanoseconds % 1000000000l))) + \ | ||
| ((double)((int32_t)((nanoseconds - ((int32_t)(nanoseconds % 1000000000l))) / 1000000000l)))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my comment in ros2/rmw_fastrtps#755 on why I'm very nervous about making this change. Basically things that were expecting integer division before are now going to get FPU division. While it may be more accurate, it also changes the expectations. This actually leads to another observation, which is that the type of All of that leads me to another thought. Maybe what we should do here is to make a new function called Thoughts?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah as we found in this review, changing the nature of the macro induces errors in testing. To be fair, it's a beneficial change, but if it causes errors in testing there's a high chance it could lead to breakages on the users' end. Though I don't think going the route of new typed function is a better option as it just adds more to the file and alters the way code is written, when I would assume users just want to use a macro, design-wise. Unless most of the macros are rebranded to typed functions, I would feel that it's just an awkward change when it comes to DX.
Yeah while rcutils and dds implementations use I would like to create more accuracy, but since there's not a effective way to deprecate macros, I doubt it's worth breaking user behavior to do so, nor is it worth expanding on.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think that adding more accurate function calls (especially if they are constexpr) and migrating where it makes sense would work?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, that's what I'm thinking we should do.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Seems fair enough to make more calls, but since
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Good point. It can't be constexpr here, but it can at least be a function, be const, and use types. Alternatively, if we wanted to use C++ and constexpr, we could move it to |
||
|
|
||
| /// Convenience macro to convert nanoseconds to milliseconds. | ||
| #define RCUTILS_NS_TO_MS(nanoseconds) ((nanoseconds) / (1000LL * 1000LL)) | ||
| /// Convenience macro to convert nanoseconds to microseconds. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.