Conversation
Signed-off-by: CursedRock17 <mtglucas1@gmail.com>
Signed-off-by: CursedRock17 <mtglucas1@gmail.com>
Signed-off-by: CursedRock17 <mtglucas1@gmail.com>
ahcorde
left a comment
There was a problem hiding this comment.
Looks good to me with green CI.
Let's put this on the queue to merge after the freeze is lifted.
fujitatomoya
left a comment
There was a problem hiding this comment.
lgtm with green CI
|
I think that before we merge this, we should have a companion PR in |
|
I'm going to roll out a fix soon, I assume the MACRO is returning
Edit: Which converts lease_duration to a nanosecond which is, throughout the entire ecosystem, given to be an |
Agreed with your analysis; that line of code should probably be: (though there is some risk of losing a bit of precision there). If you'd like to open a PR over at |
include/rcutils/time.h
Outdated
| #define RCUTILS_NS_TO_S(nanoseconds) \ | ||
| ((1e-9 * (double)((int32_t)(nanoseconds % 1000000000l))) + \ | ||
| ((double)((int32_t)((nanoseconds - ((int32_t)(nanoseconds % 1000000000l))) / 1000000000l)))) |
There was a problem hiding this comment.
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 nanoseconds is ill-defined because this is a macro.
All of that leads me to another thought. Maybe what we should do here is to make a new function called double rcutils_nanoseconds_to_seconds(double). And then we (slowly) convert uses of the macro over to that new function. That way we aren't making this change for things that don't expect it, and we can get the types right on the new function.
Thoughts?
There was a problem hiding this comment.
While it may be more accurate, it also changes the expectations.
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.
This actually leads to another observation, which is that the type of nanoseconds is ill-defined because this is a macro.
Yeah while rcutils and dds implementations use int64_t it's not necessarily common knowledge for users.
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.
There was a problem hiding this comment.
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.
I think that adding more accurate function calls (especially if they are constexpr) and migrating where it makes sense would work?
There was a problem hiding this comment.
I think that adding more accurate function calls (especially if they are constexpr) and migrating where it makes sense would work?
Yeah, that's what I'm thinking we should do.
There was a problem hiding this comment.
(especially if they are constexpr) and migrating where it makes sense would work?
Seems fair enough to make more calls, but since rcutils is essentially C repository, did we need these split functions in a different repo?
There was a problem hiding this comment.
Seems fair enough to make more calls, but since
rcutilsis essentially C repository, did we need these split functions in a different repo?
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 rcpputils, but then there are certain places it can't be used (like rcutils, rcl, rcl_action, and rmw).
Signed-off-by: CursedRock17 <mtglucas1@gmail.com>
|
In response to this comment I went with the first option of keeping everything within As I was breaking down the tests I would run into oddball tests in which a value would be too large for the original |
src/time.c
Outdated
| { | ||
| // scale the nanoseconds separately for improved accuracy | ||
| int64_t sec, nsec; | ||
| nsec = (nanoseconds % 1000000000l); |
There was a problem hiding this comment.
just a minor suggestion. can we have like RCUTILS_NANOSECS_PER_SEC for 1000000000 and use it else where? e.g RCUTILS_S_TO_NS, RCUTILS_NS_TO_S. the same thing can go to miliseconds and microseconds.
There was a problem hiding this comment.
Yeah seems like a great metric for users to have, especially if they design their own time-based algorithms and want standardization. I would figure it'll get used enough to be worth having 3 definitions.
Signed-off-by: CursedRock17 <mtglucas1@gmail.com>
This Pull Request is done in preparation for this geometry2 issue which reutilizes logic increasing accuracy in the conversion from nanoseconds to seconds. I assumed we wanted to keep these as Macros opposed to creating functions, but this would mean the Macros continue to take multiple "types" when we just want nanoseconds (int64_t). So should they stay as macros and we just remove all tests which don't take an int64 type and begin enforcing this behavior?