Skip to content
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

Improved Accuracy with RCUTILS #672

Open
wants to merge 2 commits into
base: rolling
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions tf2/src/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "rcutils/snprintf.h"
#include "rcutils/strerror.h"
#include "rcutils/time.h"
#include "tf2/time.h"

tf2::TimePoint tf2::get_now()
Expand All @@ -60,16 +61,7 @@ tf2::TimePoint tf2::timeFromSec(double t_sec)
double tf2::durationToSec(const tf2::Duration & input)
{
int64_t count = input.count();

// scale the nanoseconds separately for improved accuracy
int32_t sec, nsec;
nsec = static_cast<int32_t>(count % 1000000000l);
sec = static_cast<int32_t>((count - nsec) / 1000000000l);

double sec_double, nsec_double;
nsec_double = 1e-9 * static_cast<double>(nsec);
sec_double = static_cast<double>(sec);
return sec_double + nsec_double;
return rcutils_nanoseconds_to_seconds(count);
}

double tf2::timeToSec(const tf2::TimePoint & timepoint)
Expand Down