diff options
author | jthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5> | 2002-10-11 17:29:41 +0000 |
---|---|---|
committer | jthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5> | 2002-10-11 17:29:41 +0000 |
commit | aa5bf44a0ad0b5bdb40b66297675be1181efd3e3 (patch) | |
tree | db5504763dea4a260108987d6fb4083688e710ed /src/jtutil | |
parent | bdde4d9e604aebc4838b3d99828b96693607653f (diff) |
util.hh
* make fuzzy::tolerance a private data member and add set/get public
fns to access it ((cleaner C++ style))
fuzzy.cc
* fix template-instantiation syntax ==> now warning-free with icc 5,
hopefully this will also fix the fatal errors on the Hitachi
test_fuzzy.cc
* change error_exit() call to fprintf(stderr, ...) followed by abort()
so we don't need error_exit() and thus can compile standalone
(error_exit() now needs "cctk.h" :( )
makefile
* remove dependence on error_exit() from test_fuzzy
git-svn-id: http://svn.einsteintoolkit.org/cactus/EinsteinAnalysis/AHFinderDirect/trunk@826 f88db872-0e4f-0410-b76b-b9085cfa78c5
Diffstat (limited to 'src/jtutil')
-rw-r--r-- | src/jtutil/fuzzy.cc | 22 | ||||
-rw-r--r-- | src/jtutil/makefile | 4 | ||||
-rw-r--r-- | src/jtutil/test_fuzzy.cc | 7 | ||||
-rw-r--r-- | src/jtutil/util.hh | 15 |
4 files changed, 26 insertions, 22 deletions
diff --git a/src/jtutil/fuzzy.cc b/src/jtutil/fuzzy.cc index 18716b8..25a6793 100644 --- a/src/jtutil/fuzzy.cc +++ b/src/jtutil/fuzzy.cc @@ -21,7 +21,7 @@ template <typename fp> bool fuzzy<fp>::EQ(fp x, fp y) { fp max_abs = jtutil::max(jtutil::abs(x), jtutil::abs(y)); -fp epsilon = jtutil::max(tolerance, tolerance*max_abs); +fp epsilon = jtutil::max(tolerance_, tolerance_*max_abs); return jtutil::abs(x-y) <= epsilon; } @@ -74,19 +74,17 @@ return fuzzy<fp>::is_integer(x) // // -// Thanks to Thomas Mang <a9804814@unet.univie.ac.at> for answering -// my comp.lang.c++.moderated query on what syntax is correct here! +// Thanks to Thomas Mang <a9804814@unet.univie.ac.at> for helping +// me figure out the correct syntax here! // +// initializations of fuzzy::tolerance for each instantation we're going to make +template <> + float jtutil::fuzzy<float>::tolerance_ = 1.0e-5; // about 100 * FLT_EPSILON + +template <> + double jtutil::fuzzy<double>::tolerance_ = 1.0e-12; // about 1e4 * DBL_EPSILON + // template instantiations template class jtutil::fuzzy<float>; template class jtutil::fuzzy<double>; - -// template specializations -template <typename fp> - fp jtutil::fuzzy<fp>::tolerance = 0.0; // dummy generic version of - // fuzzy::tolerance (unused) -template <> - float jtutil::fuzzy<float>::tolerance = 1.0e-5; // about 100 * FLT_EPSILON -template <> - double jtutil::fuzzy<double>::tolerance = 1.0e-12; // about 1e4 * DBL_EPSILON diff --git a/src/jtutil/makefile b/src/jtutil/makefile index 8a7e0da..3421d0a 100644 --- a/src/jtutil/makefile +++ b/src/jtutil/makefile @@ -1,5 +1,5 @@ # Makefile for standalone test drivers in this directory -# $Header: /usr/local/svn/cvs-repositories/numrelcvs/AEIThorns/AHFinderDirect/src/jtutil/makefile,v 1.7 2002-09-29 23:05:18 jthorn Exp $ +# $Header: /usr/local/svn/cvs-repositories/numrelcvs/AEIThorns/AHFinderDirect/src/jtutil/makefile,v 1.8 2002-10-11 17:29:41 jthorn Exp $ # # CC, CXX = C and C++ compilers. Defaults are gcc and g++ if # variables aren't set from command line or environment. @@ -40,7 +40,7 @@ test_cpm_map : test_cpm_map.o cpm_map.o \ test_linear_map : test_linear_map.o linear_map.o \ fuzzy.o round.o error_exit.o -lm test_fuzzy : test_fuzzy.o fuzzy.o \ - round.o error_exit.o + round.o test_round : test_round.o round.o test_modulo : test_modulo.o miscfp.o \ fuzzy.o round.o error_exit.o -lm diff --git a/src/jtutil/test_fuzzy.cc b/src/jtutil/test_fuzzy.cc index b68d9e5..2b26f25 100644 --- a/src/jtutil/test_fuzzy.cc +++ b/src/jtutil/test_fuzzy.cc @@ -8,11 +8,11 @@ // *** template instantiations #include <stdio.h> +#include <stdlib.h> #include <assert.h> #include "stdc.h" #include "util.hh" -using jtutil::error_exit; using jtutil::fuzzy; // prototypes @@ -189,11 +189,12 @@ case '>': assert( fuzzy<fp>::GT(x,y) == true ); break; default: - error_exit(PANIC_EXIT, + fprintf(stderr, "***** check_binary<fp>: bad xy_relation=(int)'%c'\n" " (this should never happen!)\n" , - int(xy_relation)); /*NOTREACHED*/ + int(xy_relation)); + abort(); /*NOTREACHED*/ } } diff --git a/src/jtutil/util.hh b/src/jtutil/util.hh index bdc4f86..3cb2181 100644 --- a/src/jtutil/util.hh +++ b/src/jtutil/util.hh @@ -137,11 +137,10 @@ template <typename fp> class fuzzy { public: - // comparison tolerance - // ... must be explicitly initialized when instantiating - // for a new <fp> type, see "fuzzy.cc" for details/examples - // ... may be modified by user code if needed - static fp tolerance; + // comparison tolerance (may be modified by user code if needed) + static fp get_tolerance() { return tolerance_; } + static void set_tolerance(fp new_tolerance) + { tolerance_ = new_tolerance; } // fuzzy commparisons static bool EQ(fp x, fp y); @@ -154,6 +153,12 @@ public: static bool is_integer(fp x); // is x fuzzily an integer? static int floor(fp x); // round x fuzzily down to integer static int ceiling(fp x); // round x fuzzily up to integer + +private: + // comparison tolerance + // ... must be explicitly initialized when instantiating + // for a new <fp> type, see "fuzzy.cc" for details/examples + static fp tolerance_; }; //****************************************************************************** |