Goby v2
message_var_float.cpp
1 // Copyright 2009-2018 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 //
6 //
7 // This file is part of the Goby Underwater Autonomy Project Libraries
8 // ("The Goby Libraries").
9 //
10 // The Goby Libraries are free software: you can redistribute them and/or modify
11 // them under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // The Goby Libraries are distributed in the hope that they will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
22 
23 #include "message_var_float.h"
24 
25 #include "goby/util/sci.h"
26 
27 goby::transitional::DCCLMessageVarFloat::DCCLMessageVarFloat(
28  double max /*= std::numeric_limits<double>::max()*/, double min /*= 0*/,
29  double precision /*= 0*/)
30  : DCCLMessageVar(), max_(max), min_(min), precision_(precision),
31  max_delta_(std::numeric_limits<double>::quiet_NaN())
32 {
33 }
34 
35 void goby::transitional::DCCLMessageVarFloat::initialize_specific()
36 {
37  // flip max and min if needed
38  if (max_ < min_)
39  {
40  double tmp = max_;
41  max_ = min_;
42  min_ = tmp;
43  }
44 
45  if (using_delta_differencing() && max_delta_ < 0)
46  max_delta_ = -max_delta_;
47 }
48 
49 void goby::transitional::DCCLMessageVarFloat::pre_encode(DCCLMessageVal& v)
50 {
51  double r;
52  if (v.get(r))
53  v = util::unbiased_round(r, precision_);
54 }
STL namespace.