approxEqual.cpp
Go to the documentation of this file.
00001 // Copyright (C) 2007 Wim Meeussen
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 //
00017 
00018 #include "approxEqual.hpp"
00019 
00020 bool approxEqual(double a, double b, double epsilon)
00021 {
00022   return (a <= b+epsilon) && (a >= b-epsilon);
00023 }
00024 
00025 
00026 bool approxEqual(const MatrixWrapper::Matrix& a, const MatrixWrapper::Matrix& b, double epsilon)
00027 {
00028   if (a.rows() != b.rows()) return false;
00029   if (a.columns() != b.columns()) return false;
00030 
00031   for (unsigned int r=0; r<a.rows(); r++)
00032     for (unsigned int c=0; c<a.columns(); c++)
00033       if (!approxEqual(a(r+1, c+1), b(r+1,c+1),epsilon)) return false;
00034 
00035   return true;
00036 }
00037 
00038 
00039 bool approxEqual(const MatrixWrapper::SymmetricMatrix& a, const MatrixWrapper::SymmetricMatrix& b, double epsilon)
00040 {
00041   if (a.rows() != b.rows()) return false;
00042   if (a.columns() != b.columns()) return false;
00043 
00044   for (unsigned int r=0; r<a.rows(); r++)
00045     for (unsigned int c=0; c<a.columns(); c++)
00046       if (!approxEqual(a(r+1, c+1), b(r+1,c+1),epsilon)) return false;
00047 
00048   return true;
00049 }
00050 
00051 bool approxEqual(const MatrixWrapper::ColumnVector& a, const MatrixWrapper::ColumnVector& b, double epsilon)
00052 {
00053   if (a.rows() != b.rows()) return false;
00054 
00055   for (unsigned int r=0; r<a.rows(); r++)
00056     if (!approxEqual(a(r+1), b(r+1),epsilon)) return false;
00057 
00058   return true;
00059 }


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 Thu Feb 11 2016 22:31:56