duration.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #include <math.h>
19 #include "ros/duration.h"
20 
21 namespace ros
22 {
23  void normalizeSecNSecSigned(int32_t &sec, int32_t &nsec)
24  {
25  int32_t nsec_part = nsec;
26  int32_t sec_part = sec;
27 
28  while (nsec_part > 1000000000L)
29  {
30  nsec_part -= 1000000000L;
31  ++sec_part;
32  }
33  while (nsec_part < 0)
34  {
35  nsec_part += 1000000000L;
36  --sec_part;
37  }
38  sec = sec_part;
39  nsec = nsec_part;
40  }
41 
42  Duration& Duration::operator+=(const Duration &rhs)
43  {
44  sec += rhs.sec;
45  nsec += rhs.nsec;
46  normalizeSecNSecSigned(sec, nsec);
47  return *this;
48  }
49 
50  Duration& Duration::operator-=(const Duration &rhs){
51  sec += -rhs.sec;
52  nsec += -rhs.nsec;
53  normalizeSecNSecSigned(sec, nsec);
54  return *this;
55  }
56 
57  Duration& Duration::operator*=(double scale){
58  sec *= scale;
59  nsec *= scale;
60  normalizeSecNSecSigned(sec, nsec);
61  return *this;
62  }
63 
64 }
ROSTIME_DECL void normalizeSecNSecSigned(int64_t &sec, int64_t &nsec)


cob_hand_bridge
Author(s): Mathias Lüdtke
autogenerated on Tue Oct 20 2020 03:35:57