//# Math.cc: Implementation of miscellaneous functions in Math.h //# Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 //# Associated Universities, Inc. Washington DC, USA. //# //# This library is free software; you can redistribute it and/or modify it //# under the terms of the GNU Library General Public License as published by //# the Free Software Foundation; either version 2 of the License, or (at your //# option) any later version. //# //# This library is distributed in the hope that it will be useful, but WITHOUT //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public //# License for more details. //# //# You should have received a copy of the GNU Library General Public License //# along with this library; if not, write to the Free Software Foundation, //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. //# //# Correspondence concerning AIPS++ should be addressed as follows: //# Internet email: aips2-request@nrao.edu. //# Postal address: AIPS++ Project Office //# National Radio Astronomy Observatory //# 520 Edgemont Road //# Charlottesville, VA 22903-2475 USA //# //# $Id$ #include #include #include // Changes for SUN CC port - abs changed to fabs for double and float args. // the following is needed to get the finite function used in isInf #if defined (AIPS_SOLARIS) || defined(AIPS_IRIX) #include #endif namespace casacore { //# NAMESPACE CASACORE - BEGIN Bool near(uInt val1, uInt val2, Double tol) { if (tol <= 0) { return (val1 == val2); } if (val1 == val2) { return True; } else if (val1 > val2) { return (Double(val1-val2) <= tol*max(val1,val2)); } else { return (Double(val2-val1) <= tol*max(val1,val2)); } } Bool near(Int val1, Int val2, Double tol) { if (tol <=0) { return (val1 == val2); } if (val1 == val2) { return True; } if ((0 val2) { return (tol >= Double(val1 - val2)); } else { return (tol >= Double(val2 - val1)); } } Bool nearAbs(Int val1, Int val2, Double tol) { return (tol >= Double(std::abs(val2 - val1))); } Bool nearAbs(Float val1, Float val2, Double tol) { return (tol >= Double(fabs(val2 - val1))); } Bool nearAbs(Double val1, Double val2, Double tol) { return (tol >= fabs(val2 - val1)); } Float floatNaN() { static Float nanval; static Bool init = False; if (!init) { init = True; // All bits on is a NaN uChar *uptr = (uChar *)&nanval; for (uInt i=0; i= 0 ? lgr + 1.000001 : lgr - 0.000001); Double temp = val * pow(10.0, -i); return sign*round(temp)*pow(10.0, i); } } //# NAMESPACE CASACORE - END