Skip to content

time.h durationToSec seems very inefficient #34

@nate-jackson

Description

@nate-jackson

We have been investigating why we can't seem to get lookupTransform to work properly for us, and came across this function.

Instead of doing the big long thing that is going on there:

inline double durationToSec(const tf2::Duration& input){
    int64_t count = input.count();
    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;
  }

couldn't we just do

inline double durationToSec(const tf2::Duration& input){
    return input.count() * 1e-9;
  }

I can't see a reason for the extra stuff that is going on in there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions