Simbody
|
These inline functions provide a fast and convenient way for doing arithmetic with the ugly Posix timespec struct. More...
Functions | |
long long | SimTK::timespecToNs (const timespec &ts) |
Convert a time stored in a timespec struct to the equivalent number of nanoseconds (as a signed quantity). | |
void | SimTK::nsToTimespec (const long long &ns, timespec &ts) |
Given a signed number of nanoseconds, convert that into seconds and leftover nanoseconds in a timespec struct. | |
double | SimTK::nsToSec (const long long &ns) |
Given a count of nanosecond ticks as a signed 64 bit integer, return the same time interval as a double precision floating point number of seconds. | |
long long | SimTK::secToNs (const double &s) |
Given a signed time interval as a double precision floating point number of seconds, return the same time interval as a count of nanosecond ticks in a signed 64 bit integer. |
These inline functions provide a fast and convenient way for doing arithmetic with the ugly Posix timespec struct.
Use them to convert the timespec to a long long integer number of nanoseconds, do arithmetic in that form, and then convert back. Negative times are handled correctly (they come up as the result of subtraction and comparisons).
We usually prefer to deal with times as a double precision floating point number of seconds and functions are provided for converting between nanoseconds and seconds in this format.
long long SimTK::timespecToNs | ( | const timespec & | ts | ) | [inline] |
Convert a time stored in a timespec struct to the equivalent number of nanoseconds (as a signed quantity).
void SimTK::nsToTimespec | ( | const long long & | ns, |
timespec & | ts | ||
) | [inline] |
Given a signed number of nanoseconds, convert that into seconds and leftover nanoseconds in a timespec struct.
double SimTK::nsToSec | ( | const long long & | ns | ) | [inline] |
Given a count of nanosecond ticks as a signed 64 bit integer, return the same time interval as a double precision floating point number of seconds.
See Timespec/Nanosecond/Second Conversions for cautions.
long long SimTK::secToNs | ( | const double & | s | ) | [inline] |
Given a signed time interval as a double precision floating point number of seconds, return the same time interval as a count of nanosecond ticks in a signed 64 bit integer.
See Timespec/Nanosecond/Second Conversions for cautions.