running_stats_duration.hpp
Go to the documentation of this file.
1 #pragma once
2 
11 #include <cmath>
12 
14 
15 #include <ros/duration.h>
16 
17 namespace cras
18 {
19 
20 template<>
21 ::ros::Duration RunningStats<::ros::Duration>::multiply(const ::ros::Duration& val1, const ::ros::Duration& val2)
22 {
23  const auto s1 = static_cast<int64_t>(val1.sec);
24  const auto s2 = static_cast<int64_t>(val2.sec);
25  const auto ns1 = static_cast<int64_t>(val1.nsec);
26  const auto ns2 = static_cast<int64_t>(val2.nsec);
27  return ::ros::Duration().fromNSec(s1 * s2 * 1000000000LL + s1 * ns2 + s2 * ns1 + (ns1 * ns2) / 1000000000LL);
28 }
29 
30 template<>
32 {
33  return ::ros::Duration(::sqrt(val.toSec()));
34 }
35 
36 template<>
38 {
39  return {0, 0};
40 }
41 
42 template<>
44  const ::ros::WallDuration& val1, const ::ros::WallDuration& val2)
45 {
46  const auto s1 = static_cast<int64_t>(val1.sec);
47  const auto s2 = static_cast<int64_t>(val2.sec);
48  const auto ns1 = static_cast<int64_t>(val1.nsec);
49  const auto ns2 = static_cast<int64_t>(val2.nsec);
50  return ::ros::WallDuration().fromNSec(s1 * s2 * 1000000000LL + s1 * ns2 + s2 * ns1 + (ns1 * ns2) / 1000000000LL);
51 }
52 
53 template<>
55 {
56  return ::ros::WallDuration(::sqrt(val.toSec()));
57 }
58 
59 template<>
61 {
62  return {0, 0};
63 }
64 
65 }
cras::RunningStats::sqrt
static T sqrt(const T &val)
Return the square root of the given value (whatever meaning that might have).
cras
Definition: any.hpp:15
cras::RunningStats::zero
static T zero()
Return a T value representing zero.
duration.h
cras::RunningStats::multiply
static T multiply(const T &val1, const T &val2)
val1 * val2
running_stats.hpp
Computation of running average and variance using Welford's algorithm.
ros::WallDuration
ros::Duration


cras_cpp_common
Author(s): Martin Pecka
autogenerated on Tue Nov 26 2024 03:49:04