approxEqual.cpp
Go to the documentation of this file.
1 // Copyright (C) 2007 Wim Meeussen
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 
18 #include "approxEqual.hpp"
19 
20 bool approxEqual(double a, double b, double epsilon)
21 {
22  return (a <= b+epsilon) && (a >= b-epsilon);
23 }
24 
25 
26 bool approxEqual(const MatrixWrapper::Matrix& a, const MatrixWrapper::Matrix& b, double epsilon)
27 {
28  if (a.rows() != b.rows()) return false;
29  if (a.columns() != b.columns()) return false;
30 
31  for (unsigned int r=0; r<a.rows(); r++)
32  for (unsigned int c=0; c<a.columns(); c++)
33  if (!approxEqual(a(r+1, c+1), b(r+1,c+1),epsilon)) return false;
34 
35  return true;
36 }
37 
38 
39 bool approxEqual(const MatrixWrapper::SymmetricMatrix& a, const MatrixWrapper::SymmetricMatrix& b, double epsilon)
40 {
41  if (a.rows() != b.rows()) return false;
42  if (a.columns() != b.columns()) return false;
43 
44  for (unsigned int r=0; r<a.rows(); r++)
45  for (unsigned int c=0; c<a.columns(); c++)
46  if (!approxEqual(a(r+1, c+1), b(r+1,c+1),epsilon)) return false;
47 
48  return true;
49 }
50 
51 bool approxEqual(const MatrixWrapper::ColumnVector& a, const MatrixWrapper::ColumnVector& b, double epsilon)
52 {
53  if (a.rows() != b.rows()) return false;
54 
55  for (unsigned int r=0; r<a.rows(); r++)
56  if (!approxEqual(a(r+1), b(r+1),epsilon)) return false;
57 
58  return true;
59 }
bool approxEqual(double a, double b, double epsilon)
Definition: approxEqual.cpp:20


bfl
Author(s): Klaas Gadeyne, Wim Meeussen, Tinne Delaet and many others. See web page for a full contributor list. ROS package maintained by Wim Meeussen.
autogenerated on Mon Jun 10 2019 12:47:58