diff options
author | jthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5> | 2001-07-03 14:27:46 +0000 |
---|---|---|
committer | jthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5> | 2001-07-03 14:27:46 +0000 |
commit | 1d094f7721acde19cf180b17281f0ab77e99c3ef (patch) | |
tree | 0ab04d94c83b12ab8e4ca49d72a322031937156f | |
parent | ba32debaf88fedd6f7d772b400eb4266a0aaa97d (diff) |
s/fpt/fp/g as template parameter
git-svn-id: http://svn.einsteintoolkit.org/cactus/EinsteinAnalysis/AHFinderDirect/trunk@125 f88db872-0e4f-0410-b76b-b9085cfa78c5
-rw-r--r-- | src/jtutil/array.cc | 56 | ||||
-rw-r--r-- | src/jtutil/array.hh | 72 | ||||
-rw-r--r-- | src/jtutil/fuzzy.cc | 38 | ||||
-rw-r--r-- | src/jtutil/linear_map.cc | 94 | ||||
-rw-r--r-- | src/jtutil/linear_map.hh | 46 | ||||
-rw-r--r-- | src/jtutil/round.cc | 16 | ||||
-rw-r--r-- | src/jtutil/test_fuzzy.cc | 94 | ||||
-rw-r--r-- | src/jtutil/test_round.cc | 8 | ||||
-rw-r--r-- | src/jtutil/util.hh | 78 |
9 files changed, 251 insertions, 251 deletions
diff --git a/src/jtutil/array.cc b/src/jtutil/array.cc index 1936bb8..34ea1e0 100644 --- a/src/jtutil/array.cc +++ b/src/jtutil/array.cc @@ -29,18 +29,18 @@ // // This function constructs an array1d object. // -template <typename fpt> -array1d<fpt>::array1d(int min_i_in, int max_i_in, - fpt *array_in = NULL) +template <typename fp> +array1d<fp>::array1d(int min_i_in, int max_i_in, + fp *array_in = NULL) : min_i_(min_i_in), max_i_(max_i_in), we_own_array_(array_in == NULL) { -array_ = we_own_array_ ? new fpt[N_i()] : array_in; +array_ = we_own_array_ ? new fp[N_i()] : array_in; // need to explicitly initialize -- new[] *doesn't* do this automagically for (int i = 0 ; i < N_array() ; ++i) { - array_[i] = fpt(0); + array_[i] = fp(0); } } @@ -49,8 +49,8 @@ array_ = we_own_array_ ? new fpt[N_i()] : array_in; // // This function destroys an array1d object. // -template <typename fpt> -array1d<fpt>::~array1d() +template <typename fp> +array1d<fp>::~array1d() { if (we_own_array_) then delete[] array_; @@ -63,22 +63,22 @@ if (we_own_array_) // // This function constructs an array2d object. // -template <typename fpt> -array2d<fpt>::array2d(int min_i_in, int max_i_in, +template <typename fp> +array2d<fp>::array2d(int min_i_in, int max_i_in, int min_j_in, int max_j_in, - fpt *array_in = NULL) + fp *array_in = NULL) : min_i_(min_i_in), max_i_(max_i_in), min_j_(min_j_in), max_j_(max_j_in), we_own_array_(array_in == NULL) { stride_i_ = N_j(); N_array_ = N_i() * stride_i_; -array_ = we_own_array_ ? new fpt[N_array_] : array_in; +array_ = we_own_array_ ? new fp[N_array_] : array_in; // need to explicitly initialize -- new[] *doesn't* do this automagically for (int i = 0 ; i < N_array() ; ++i) { - array_[i] = fpt(0); + array_[i] = fp(0); } offset_ = 0; // temp value, needed for following subscript() call @@ -91,8 +91,8 @@ offset_ = - subscript_unchecked(min_i_, min_j_); // // This function destroys an array2d object. // -template <typename fpt> -array2d<fpt>::~array2d() +template <typename fp> +array2d<fp>::~array2d() { if (we_own_array_) then delete[] array_; @@ -105,11 +105,11 @@ if (we_own_array_) // // This function constructs an array3d object. // -template <typename fpt> -array3d<fpt>::array3d(int min_i_in, int max_i_in, +template <typename fp> +array3d<fp>::array3d(int min_i_in, int max_i_in, int min_j_in, int max_j_in, int min_k_in, int max_k_in, - fpt *array_in = NULL) + fp *array_in = NULL) : min_i_(min_i_in), max_i_(max_i_in), min_j_(min_j_in), max_j_(max_j_in), min_k_(min_k_in), max_k_(max_k_in), @@ -118,12 +118,12 @@ array3d<fpt>::array3d(int min_i_in, int max_i_in, stride_j_ = N_k(); stride_i_ = N_j() * stride_j_; N_array_ = N_i() * stride_i_; -array_ = we_own_array_ ? new fpt[N_array_] : array_in; +array_ = we_own_array_ ? new fp[N_array_] : array_in; // need to explicitly initialize -- new[] *doesn't* do this automagically for (int i = 0 ; i < N_array() ; ++i) { - array_[i] = fpt(0); + array_[i] = fp(0); } offset_ = 0; // temp value, needed for following subscript() call @@ -136,8 +136,8 @@ offset_ = - subscript_unchecked(min_i_, min_j_, min_k_); // // This function destroys an array3d object. // -template <typename fpt> -array3d<fpt>::~array3d() +template <typename fp> +array3d<fp>::~array3d() { if (we_own_array_) then delete[] array_; @@ -150,12 +150,12 @@ if (we_own_array_) // // This function constructs an array4d object. // -template <typename fpt> -array4d<fpt>::array4d(int min_i_in, int max_i_in, +template <typename fp> +array4d<fp>::array4d(int min_i_in, int max_i_in, int min_j_in, int max_j_in, int min_k_in, int max_k_in, int min_l_in, int max_l_in, - fpt *array_in = NULL) + fp *array_in = NULL) : min_i_(min_i_in), max_i_(max_i_in), min_j_(min_j_in), max_j_(max_j_in), min_k_(min_k_in), max_k_(max_k_in), @@ -166,12 +166,12 @@ stride_k_ = N_l(); stride_j_ = N_k() * stride_k_; stride_i_ = N_j() * stride_j_; N_array_ = N_i() * stride_i_; -array_ = we_own_array_ ? new fpt[N_array_] : array_in; +array_ = we_own_array_ ? new fp[N_array_] : array_in; // need to explicitly initialize -- new[] *doesn't* do this automagically for (int i = 0 ; i < N_array() ; ++i) { - array_[i] = fpt(0); + array_[i] = fp(0); } offset_ = 0; // temp value, needed for following subscript() call @@ -184,8 +184,8 @@ offset_ = - subscript_unchecked(min_i_, min_j_, min_k_, min_l_); // // This function destroys an array4d object. // -template <typename fpt> -array4d<fpt>::~array4d() +template <typename fp> +array4d<fp>::~array4d() { if (we_own_array_) then delete[] array_; diff --git a/src/jtutil/array.hh b/src/jtutil/array.hh index 2e8cd95..0617627 100644 --- a/src/jtutil/array.hh +++ b/src/jtutil/array.hh @@ -58,7 +58,7 @@ //****************************************************************************** -template <typename fpt> +template <typename fp> class array1d { public: @@ -71,13 +71,13 @@ public: // normal-use access functions // ... rvalue - fpt operator()(int i) const + fp operator()(int i) const { assert( is_valid_subscript(i) ); return array_[i - min_i_]; } // ... lvalue - fpt& operator()(int i) + fp& operator()(int i) { assert( is_valid_subscript(i) ); return array_[i - min_i_]; @@ -86,12 +86,12 @@ public: // get access to internal 0-origin 1D storage array // (low-level, dangerous, use with caution!) int N_array() const { return N_i(); } - fpt* get_array() const { return array_; } + fp* get_array() const { return array_; } // constructor, destructor - // constructor initializes all array elements to fpt(0.0) + // constructor initializes all array elements to fp(0.0) array1d(int min_i_in, int max_i_in, - fpt *array_in = NULL); // caller-provided storage array + fp *array_in = NULL); // caller-provided storage array // if non-NULL ~array1d(); @@ -99,14 +99,14 @@ private: // we forbid copying and passing by value // by declaring the copy constructor and assignment operator // private, but never defining them - array1d(const array1d<fpt>& rhs); - array1d<fpt>& operator=(const array1d<fpt>& rhs); + array1d(const array1d<fp>& rhs); + array1d<fp>& operator=(const array1d<fp>& rhs); private: // note we declare the array pointer first in the class // ==> it's probably at 0 offset // ==> we may get slightly faster array access - fpt* array_; + fp* array_; // min/max array bounds const int min_i_, max_i_; @@ -117,7 +117,7 @@ private: //****************************************************************************** -template <typename fpt> +template <typename fp> class array2d { public: @@ -153,22 +153,22 @@ public: // normal-use access functions // ... rvalue - fpt operator()(int i, int j) const + fp operator()(int i, int j) const { return array_[ subscript(i,j) ]; } // ... lvalue - fpt& operator()(int i, int j) + fp& operator()(int i, int j) { return array_[ subscript(i,j) ]; } // get access to internal 0-origin 1D storage array // (low-level, dangerous, use with caution!) int N_array() const { return N_array_; } - fpt* get_array() const { return array_; } + fp* get_array() const { return array_; } // constructor, destructor - // constructor initializes all array elements to fpt(0.0) + // constructor initializes all array elements to fp(0.0) array2d(int min_i_in, int max_i_in, int min_j_in, int max_j_in, - fpt *array_in = NULL); // caller-provided storage array + fp *array_in = NULL); // caller-provided storage array // if non-NULL ~array2d(); @@ -176,14 +176,14 @@ private: // we forbid copying and passing by value // by declaring the copy constructor and assignment operator // private, but never defining them - array2d(const array2d<fpt>& rhs); - array2d<fpt>& operator=(const array2d<fpt>& rhs); + array2d(const array2d<fp>& rhs); + array2d<fp>& operator=(const array2d<fp>& rhs); private: // n.b. we declare the array pointer first in the class // ==> it's probably at 0 offset // ==> we may get slightly faster array access - fpt* array_; // --> new-allocated 1D storage array + fp* array_; // --> new-allocated 1D storage array // subscripting info // n.b. put this next in class so it should be in the same @@ -202,7 +202,7 @@ private: //****************************************************************************** -template <typename fpt> +template <typename fp> class array3d { public: @@ -242,23 +242,23 @@ public: // normal-use access functions // ... rvalue - fpt operator()(int i, int j, int k) const + fp operator()(int i, int j, int k) const { return array_[ subscript(i,j,k) ]; } // ... lvalue - fpt& operator()(int i, int j, int k) + fp& operator()(int i, int j, int k) { return array_[ subscript(i,j,k) ]; } // get access to internal 0-origin 1D storage array // (low-level, dangerous, use with caution!) int N_array() const { return N_array_; } - fpt* get_array() const { return array_; } + fp* get_array() const { return array_; } // constructor, destructor - // constructor initializes all array elements to fpt(0.0) + // constructor initializes all array elements to fp(0.0) array3d(int min_i_in, int max_i_in, int min_j_in, int max_j_in, int min_k_in, int max_k_in, - fpt *array_in = NULL); // caller-provided storage array + fp *array_in = NULL); // caller-provided storage array // if non-NULL ~array3d(); @@ -266,14 +266,14 @@ private: // we forbid copying and passing by value // by declaring the copy constructor and assignment operator // private, but never defining them - array3d(const array3d<fpt>& rhs); - array3d<fpt>& operator=(const array3d<fpt>& rhs); + array3d(const array3d<fp>& rhs); + array3d<fp>& operator=(const array3d<fp>& rhs); private: // note we declare the array pointer first in the class // ==> it's probably at 0 offset // ==> we may get slightly faster array access - fpt* array_; // --> new-allocated 1D storage array + fp* array_; // --> new-allocated 1D storage array // subscripting info // n.b. put this next in class so it should be in the same @@ -293,7 +293,7 @@ private: //****************************************************************************** -template <typename fpt> +template <typename fp> class array4d { public: @@ -343,24 +343,24 @@ public: // normal-use access functions // ... rvalue - fpt operator()(int i, int j, int k, int l) const + fp operator()(int i, int j, int k, int l) const { return array_[ subscript(i,j,k,l) ]; } // ... lvalue - fpt& operator()(int i, int j, int k, int l) + fp& operator()(int i, int j, int k, int l) { return array_[ subscript(i,j,k,l) ]; } // get access to internal 0-origin 1D storage array // (low-level, dangerous, use with caution!) int N_array() const { return N_array_; } - fpt* get_array() const { return array_; } + fp* get_array() const { return array_; } // constructor, destructor - // constructor initializes all array elements to fpt(0.0) + // constructor initializes all array elements to fp(0.0) array4d(int min_i_in, int max_i_in, int min_j_in, int max_j_in, int min_k_in, int max_k_in, int min_l_in, int max_l_in, - fpt *array_in = NULL); // caller-provided storage array + fp *array_in = NULL); // caller-provided storage array // if non-NULL ~array4d(); @@ -368,14 +368,14 @@ private: // we forbid copying and passing by value // by declaring the copy constructor and assignment operator // private, but never defining them - array4d(const array4d<fpt>& rhs); - array4d<fpt>& operator=(const array4d<fpt>& rhs); + array4d(const array4d<fp>& rhs); + array4d<fp>& operator=(const array4d<fp>& rhs); private: // note we declare the array pointer first in the class // ==> it's probably at 0 offset // ==> we may get slightly faster array access - fpt* array_; // --> new-allocated 1D storage array + fp* array_; // --> new-allocated 1D storage array // subscripting info // n.b. put this next in class so it should be in the same diff --git a/src/jtutil/fuzzy.cc b/src/jtutil/fuzzy.cc index 98b71ab..1ebfe54 100644 --- a/src/jtutil/fuzzy.cc +++ b/src/jtutil/fuzzy.cc @@ -15,42 +15,42 @@ //****************************************************************************** -template <typename fpt> -bool fuzzy<fpt>::EQ(fpt x, fpt y) +template <typename fp> +bool fuzzy<fp>::EQ(fp x, fp y) { -fpt max_abs = jtutil::max(jtutil::abs(x), jtutil::abs(y)); -fpt epsilon = jtutil::max(tolerance, tolerance*max_abs); +fp max_abs = jtutil::max(jtutil::abs(x), jtutil::abs(y)); +fp epsilon = jtutil::max(tolerance, tolerance*max_abs); -return jtutil::abs<fpt>(x-y) <= epsilon; +return jtutil::abs<fp>(x-y) <= epsilon; } //****************************************************************************** -template <typename fpt> -bool fuzzy<fpt>::is_integer(fpt x) +template <typename fp> +bool fuzzy<fp>::is_integer(fp x) { -int i = round<fpt>::to_integer(x); -return EQ(x, fpt(i)); +int i = round<fp>::to_integer(x); +return EQ(x, fp(i)); } //****************************************************************************** -template <typename fpt> -int fuzzy<fpt>::floor(fpt x) +template <typename fp> +int fuzzy<fp>::floor(fp x) { -return fuzzy<fpt>::is_integer(x) - ? round<fpt>::to_integer(x) - : round<fpt>::floor(x); +return fuzzy<fp>::is_integer(x) + ? round<fp>::to_integer(x) + : round<fp>::floor(x); } //****************************************************************************** -template <typename fpt> -int fuzzy<fpt>::ceiling(fpt x) +template <typename fp> +int fuzzy<fp>::ceiling(fp x) { -return fuzzy<fpt>::is_integer(x) - ? round<fpt>::to_integer(x) - : round<fpt>::ceiling(x); +return fuzzy<fp>::is_integer(x) + ? round<fp>::to_integer(x) + : round<fp>::ceiling(x); } //****************************************************************************** diff --git a/src/jtutil/linear_map.cc b/src/jtutil/linear_map.cc index 281bed4..09928ce 100644 --- a/src/jtutil/linear_map.cc +++ b/src/jtutil/linear_map.cc @@ -3,8 +3,8 @@ // // linear_map::linear_map - basic constructor // linear_map::linear_map - constructor for subrange of existing linear_map -// linear_map::fp_int_of_fp - convert fpt --> int coord, return as fpt -// linear_map::int_of_fp - convert fpt --> int, check for being fuzzily integral +// linear_map::fp_int_of_fp - convert fp --> int coord, return as fp +// linear_map::int_of_fp - convert fp --> int, check for being fuzzily integral // linear_map::delta_int_of_delta_fp - ... same for spacings (delta_* values) // // ***** template instantiation ***** @@ -24,11 +24,11 @@ using jtutil::error_exit; //****************************************************************************** // -// This function constructs a linear_map<fpt> object. +// This function constructs a linear_map<fp> object. // -template <typename fpt> -linear_map<fpt>::linear_map(int min_int_in, int max_int_in, - fpt min_fp_in, fpt delta_fp_in, fpt max_fp_in) +template <typename fp> +linear_map<fp>::linear_map(int min_int_in, int max_int_in, + fp min_fp_in, fp delta_fp_in, fp max_fp_in) : delta_(delta_fp_in), inverse_delta_(1.0 / delta_fp_in), min_int_(min_int_in), max_int_(max_int_in) { @@ -38,18 +38,18 @@ constructor_common(min_fp_in, max_fp_in); //****************************************************************************** // -// This function constructs a linear_map<fpt> object with a subrange +// This function constructs a linear_map<fp> object with a subrange // of an existing one. // -template <typename fpt> -linear_map<fpt>::linear_map(const linear_map<fpt> &lm_in, +template <typename fp> +linear_map<fp>::linear_map(const linear_map<fp> &lm_in, int min_int_in, int max_int_in) // subrange : delta_(lm_in.delta_fp()), inverse_delta_(lm_in.inverse_delta_fp()), min_int_(min_int_in), max_int_(max_int_in) { if (! (is_in_range(min_int_in) && is_in_range(max_int_in)) ) then error_exit(ERROR_EXIT, -"***** linear_map<fpt>::linear_map:\n" +"***** linear_map<fp>::linear_map:\n" " min_int_in=%d and/or max_int_in=%d\n" " aren't in integer range [%d,%d] of existing linear_map!\n" , @@ -64,10 +64,10 @@ constructor_common(lm_in.fp_of_int_unchecked(min_int_in), // // This function does the common argument validation and setup for -// all the constructors of class linear_map<fpt>:: . +// all the constructors of class linear_map<fp>:: . // -template <typename fpt> -void linear_map<fpt>::constructor_common(fpt min_fp_in, fpt max_fp_in) +template <typename fp> +void linear_map<fp>::constructor_common(fp min_fp_in, fp max_fp_in) // assumes // min_int_, max_int_, delta_, inverse_delta_ // are already initialized @@ -78,14 +78,14 @@ offset_ = 0.0; // temp value offset_ = min_fp_in - fp_of_int_unchecked(min_int()); // this should be guaranteed by the above calculation -assert(fuzzy<fpt>::EQ(fp_of_int_unchecked(min_int()), min_fp_in)); +assert(fuzzy<fp>::EQ(fp_of_int_unchecked(min_int()), min_fp_in)); // this is a test of the consistency of the input arguments -if (fuzzy<fpt>::NE(fp_of_int_unchecked(max_int()), max_fp_in)) +if (fuzzy<fp>::NE(fp_of_int_unchecked(max_int()), max_fp_in)) then error_exit(ERROR_EXIT, -"***** linear_map<fpt>::linear_map:\n" +"***** linear_map<fp>::linear_map:\n" " int range [%d,%d]\n" -" and fpt range [%g(%g)%g]\n" +" and fp range [%g(%g)%g]\n" " are (fuzzily) inconsistent!\n" , min_int(), max_int(), @@ -96,17 +96,17 @@ if (fuzzy<fpt>::NE(fp_of_int_unchecked(max_int()), max_fp_in)) //****************************************************************************** // -// This function converts fpt --> int coordinate, returning the result -// as an fpt (which need not be fuzzily integral). +// This function converts fp --> int coordinate, returning the result +// as an fp (which need not be fuzzily integral). // -template <typename fpt> -fpt linear_map<fpt>::fp_int_of_fp(fpt x) +template <typename fp> +fp linear_map<fp>::fp_int_of_fp(fp x) const { if (! is_in_range(x)) then error_exit(ERROR_EXIT, -"***** linear_map<fpt>::fp_int_of_fp:\n" -" fpt value x=%g is (fuzzily) outside the grid!\n" +"***** linear_map<fp>::fp_int_of_fp:\n" +" fp value x=%g is (fuzzily) outside the grid!\n" " {min(delta)max}_fp = %g(%g)%g\n" , double(x), @@ -119,29 +119,29 @@ return inverse_delta_ * (x - offset_); //****************************************************************************** // -// This function converts fpt --> int and checks that the result is +// This function converts fp --> int and checks that the result is // fuzzily integral. (The nia argument specifies what to do if the // result *isn't* fuzzily integral.) // // FIXME: -// Having to explicitly specify the global namespace for ::round<fpt>:: +// Having to explicitly specify the global namespace for ::round<fp>:: // is ++ugly. :( // -template <typename fpt> -int linear_map<fpt>::int_of_fp(fpt x, noninteger_action nia = error) +template <typename fp> +int linear_map<fp>::int_of_fp(fp x, noninteger_action nia = error) const { -const fpt fp_int = fp_int_of_fp(x); +const fp fp_int = fp_int_of_fp(x); -if (fuzzy<fpt>::is_integer(fp_int)) +if (fuzzy<fp>::is_integer(fp_int)) then { // x is (fuzzily) a grid point ==> return that - return ::round<fpt>::to_integer(fp_int); // *** EARLY RETURN *** + return ::round<fp>::to_integer(fp_int); // *** EARLY RETURN *** } // get to here ==> x isn't (fuzzily) a grid point static const char *const noninteger_msg = - "%s linear_map<fpt>::int_of_fp:\n" + "%s linear_map<fp>::int_of_fp:\n" " x=%g isn't (fuzzily) a grid point!\n" " {min(delta)max}_fp() = %g(%g)%g\n" ; @@ -163,17 +163,17 @@ case warning: // fall through case round: - return ::round<fpt>::to_integer(fp_int); // *** EARLY RETURN *** + return ::round<fp>::to_integer(fp_int); // *** EARLY RETURN *** case floor: - return ::round<fpt>::floor(fp_int); // *** EARLY RETURN *** + return ::round<fp>::floor(fp_int); // *** EARLY RETURN *** case ceiling: - return ::round<fpt>::ceiling(fp_int); // *** EARLY RETURN *** + return ::round<fp>::ceiling(fp_int); // *** EARLY RETURN *** default: error_exit(PANIC_EXIT, -"***** linear_map<fpt>::int_of_fp: illegal nia=(int)%d\n" +"***** linear_map<fp>::int_of_fp: illegal nia=(int)%d\n" " (this should never happen!)\n" , int(nia)); /*NOTREACHED*/ @@ -185,32 +185,32 @@ return 0; // dummy return to quiet gcc //****************************************************************************** // -// This function converts "delta" spacings in the fpt coordinate to +// This function converts "delta" spacings in the fp coordinate to // corresponding "delta" spacings in the int coordinate, and checks that // the result is fuzzily integral. (The nia argument specifies what to // do if the result *isn't* fuzzily integral.) // // FIXME: -// Having to explicitly specify the global namespace for ::round<fpt>:: +// Having to explicitly specify the global namespace for ::round<fp>:: // is ++ugly. :( // -template <typename fpt> -int linear_map<fpt>::delta_int_of_delta_fp(fpt delta_x, +template <typename fp> +int linear_map<fp>::delta_int_of_delta_fp(fp delta_x, noninteger_action nia = error) const { -const fpt fp_delta_int = inverse_delta_ * delta_x; +const fp fp_delta_int = inverse_delta_ * delta_x; -if (fuzzy<fpt>::is_integer(fp_delta_int)) +if (fuzzy<fp>::is_integer(fp_delta_int)) then { // delta_x is (fuzzily) an integer number of grid spacings // ==> return that - return ::round<fpt>::to_integer(fp_delta_int); // *** EARLY RETURN *** + return ::round<fp>::to_integer(fp_delta_int); // *** EARLY RETURN *** } // get to here ==> delta_x isn't (fuzzily) an integer number of grid spacings static const char *const noninteger_msg = - "%s linear_map<fpt>::delta_int_of_delta_fp:\n" + "%s linear_map<fp>::delta_int_of_delta_fp:\n" " delta_x=%g isn't (fuzzily) an integer number of grid spacings!\n" " {min(delta)max}_fp() = %g(%g)%g\n" ; @@ -232,17 +232,17 @@ case warning: // fall through case round: - return ::round<fpt>::to_integer(fp_delta_int); // *** EARLY RETURN *** + return ::round<fp>::to_integer(fp_delta_int); // *** EARLY RETURN *** case floor: - return ::round<fpt>::floor(fp_delta_int); // *** EARLY RETURN *** + return ::round<fp>::floor(fp_delta_int); // *** EARLY RETURN *** case ceiling: - return ::round<fpt>::ceiling(fp_delta_int); // *** EARLY RETURN *** + return ::round<fp>::ceiling(fp_delta_int); // *** EARLY RETURN *** default: error_exit(PANIC_EXIT, -"***** linear_map<fpt>::delta_int_of_delta_fp: illegal nia=(int)%d\n" +"***** linear_map<fp>::delta_int_of_delta_fp: illegal nia=(int)%d\n" " (this should never happen!)\n" , int(nia)); /*NOTREACHED*/ diff --git a/src/jtutil/linear_map.hh b/src/jtutil/linear_map.hh index 020a506..ac427b0 100644 --- a/src/jtutil/linear_map.hh +++ b/src/jtutil/linear_map.hh @@ -24,7 +24,7 @@ //***************************************************************************** -template <typename fpt> +template <typename fp> class linear_map { public: @@ -44,30 +44,30 @@ public: else return i; } - // convert int --> fpt - fpt fp_of_int_unchecked(int i) const + // convert int --> fp + fp fp_of_int_unchecked(int i) const { return offset_ + delta_*i; } - fpt fp_of_int(int i) const + fp fp_of_int(int i) const { assert(is_in_range(i)); return fp_of_int_unchecked(i); } // converg delta_int --> delta_fp - fpt delta_fp_of_delta_int(int delta_i) const + fp delta_fp_of_delta_int(int delta_i) const { return delta_ * delta_i; } - // fpt bounds info - fpt min_fp() const { return fp_of_int_unchecked(min_int_); } - fpt delta_fp() const { return delta_; } - fpt inverse_delta_fp() const { return inverse_delta_; } - fpt max_fp() const { return fp_of_int_unchecked(max_int_); } - bool is_in_range(fpt x) const + // fp bounds info + fp min_fp() const { return fp_of_int_unchecked(min_int_); } + fp delta_fp() const { return delta_; } + fp inverse_delta_fp() const { return inverse_delta_; } + fp max_fp() const { return fp_of_int_unchecked(max_int_); } + bool is_in_range(fp x) const { - return fuzzy<fpt>::GE(x,min_fp()) - && fuzzy<fpt>::LE(x,max_fp()); + return fuzzy<fp>::GE(x,min_fp()) + && fuzzy<fp>::LE(x,max_fp()); } - fpt clamp(fpt x) const + fp clamp(fp x) const { if (x < min_fp()) then return min_fp(); @@ -80,9 +80,9 @@ public: int zero_origin_int(int i) const { return i - min_int(); } int map_int(int zero_origin_i) { return zero_origin_i + min_int(); } - // convert fp --> int coordinate, but return result as fpt + // convert fp --> int coordinate, but return result as fp // (which need not be fuzzily integral) - fpt fp_int_of_fp(fpt x) const; + fp fp_int_of_fp(fp x) const; // convert fp --> int, check being fuzzily integral enum noninteger_action // what to do if "int" @@ -94,17 +94,17 @@ public: floor, // (silently) round to -infinity ceiling // (silently) round to +infinity }; - int int_of_fp(fpt x, noninteger_action nia = error) const; + int int_of_fp(fp x, noninteger_action nia = error) const; // convert delta_fp --> delta_int, check being fuzzily integral - int delta_int_of_delta_fp(fpt delta_x, noninteger_action nia = error) + int delta_int_of_delta_fp(fp delta_x, noninteger_action nia = error) const; // constructors linear_map(int min_int_in, int max_int_in, - fpt min_fp_in, fpt delta_fp_in, fpt max_fp_in); + fp min_fp_in, fp delta_fp_in, fp max_fp_in); // ... construct with subrange of existing linear_map - linear_map(const linear_map<fpt> &lm_in, + linear_map(const linear_map<fp> &lm_in, int min_int_in, int max_int_in); // no need for explicit destructor, compiler-generated no-op is ok @@ -116,16 +116,16 @@ private: // common code (argument validation & setup) for all constructors // assumes min_int_, max_int_, delta_ already initialized, // other class members *not* initialized - void constructor_common(fpt min_fp_in, fpt max_fp_in); + void constructor_common(fp min_fp_in, fp max_fp_in); // these define the actual mapping // via the fp_of_int() function (above) - fpt offset_, delta_; + fp offset_, delta_; // cache of 1.0/delta_ // ==> avoids fp divide in inverse_delta_fp() // ==> also makes fp --> int conversions slightly faster - fpt inverse_delta_; + fp inverse_delta_; // bounds (inclusive) const int min_int_, max_int_; diff --git a/src/jtutil/round.cc b/src/jtutil/round.cc index 1e20af9..7ac60f1 100644 --- a/src/jtutil/round.cc +++ b/src/jtutil/round.cc @@ -20,15 +20,15 @@ // *** Implementation Notes *** // // We assume throughout this code that C++'s "built-in" conversion -// from <fpt> to integer takes the floor, at least for zero or positive +// from <fp> to integer takes the floor, at least for zero or positive // values. // //****************************************************************************** // round to nearest integer, up for exact tie -template <typename fpt> -int round<fpt>::to_integer(fpt x) +template <typename fp> +int round<fp>::to_integer(fp x) { return (x >= 0.0) ? int(x + 0.5) // eg 3.6 --> int(4.1) = 4 @@ -37,8 +37,8 @@ return (x >= 0.0) //****************************************************************************** -template <typename fpt> -int round<fpt>::floor(fpt x) +template <typename fp> +int round<fp>::floor(fp x) { return (x >= 0.0) ? int(x) @@ -47,11 +47,11 @@ return (x >= 0.0) //****************************************************************************** -template <typename fpt> -int round<fpt>::ceiling(fpt x) +template <typename fp> +int round<fp>::ceiling(fp x) { return (x >= 0.0) - ? int(x) + (x != fpt(int(x))) + ? int(x) + (x != fp(int(x))) : - floor(-x); } diff --git a/src/jtutil/test_fuzzy.cc b/src/jtutil/test_fuzzy.cc index 38bd7db..0f0622e 100644 --- a/src/jtutil/test_fuzzy.cc +++ b/src/jtutil/test_fuzzy.cc @@ -2,9 +2,9 @@ // $Id$ // // main -// check<fpt> -// check_binary<fpt> -// check_unary<fpt> +// check<fp> +// check_binary<fp> +// check_unary<fp> // *** template instantiations #include <stdio.h> @@ -14,19 +14,19 @@ using jtutil::error_exit; // prototypes -template <typename fpt> +template <typename fp> void check(const char* print_string, - fpt x, fpt y, + fp x, fp y, char xy_relation, bool unary_flag, bool x_is_fuzzy_integer, int fuzzy_floor_of_x, int fuzzy_ceiling_of_x); -template <typename fpt> - void check_binary(fpt x, fpt y, +template <typename fp> + void check_binary(fp x, fp y, char xy_relation); -template <typename fpt> - void check_unary(fpt x, +template <typename fp> + void check_unary(fp x, bool x_is_fuzzy_integer, int fuzzy_floor_of_x, int fuzzy_ceiling_of_x); @@ -102,13 +102,13 @@ return 0; // // This function template is a driver to do all the tests for a single -// argument or pair of arguments. It calls check_binary<fpt>() to do the -// binary-function tests, and optionally calls check_unary<fpt>() to do the +// argument or pair of arguments. It calls check_binary<fp>() to do the +// binary-function tests, and optionally calls check_unary<fp>() to do the // unary-function tests. // -template <typename fpt> +template <typename fp> void check(const char* print_string, - fpt x, fpt y, + fp x, fp y, char xy_relation, bool unary_flag, bool x_is_fuzzy_integer, @@ -121,7 +121,7 @@ if (print_string != NULL) unary_flag ? "op(x,y) + op(x)" : "op(x,y) only ", double(x), double(y)); -check_binary<fpt>(x, y, xy_relation); +check_binary<fp>(x, y, xy_relation); if (unary_flag) then check_unary(x, x_is_fuzzy_integer, fuzzy_floor_of_x, fuzzy_ceiling_of_x); @@ -131,20 +131,20 @@ if (unary_flag) // // This function template tests the binary relations -// fuzzy<fpt>::EQ() -// fuzzy<fpt>::NE() -// fuzzy<fpt>::LT() -// fuzzy<fpt>::GT() -// fuzzy<fpt>::LE() -// fuzzy<fpt>::GE() +// fuzzy<fp>::EQ() +// fuzzy<fp>::NE() +// fuzzy<fp>::LT() +// fuzzy<fp>::GT() +// fuzzy<fp>::LE() +// fuzzy<fp>::GE() // for a single argument. // // The xy_relation argument must be one of '<', '=', or '>', indicating // the desired fuzzy relationship between the two arguments. The function // infers the correct values of the binary functions from this. // -template <typename fpt> - void check_binary(fpt x, fpt y, +template <typename fp> + void check_binary(fp x, fp y, char xy_relation) { // @@ -152,14 +152,14 @@ template <typename fpt> // // trichotomy (we have exactly one of <, =, > -assert( fuzzy<fpt>::LT(x,y) + fuzzy<fpt>::EQ(x,y) + fuzzy<fpt>::GT(x,y) == 1 ); +assert( fuzzy<fp>::LT(x,y) + fuzzy<fp>::EQ(x,y) + fuzzy<fp>::GT(x,y) == 1 ); // consistency of EQ() with NE() -assert( fuzzy<fpt>::NE(x,y) == ! fuzzy<fpt>::EQ(x,y) ); +assert( fuzzy<fp>::NE(x,y) == ! fuzzy<fp>::EQ(x,y) ); // consistency of LE() with LT() and EQ(), GE() with GT() and EQ() -assert( fuzzy<fpt>::LE(x,y) == (fuzzy<fpt>::LT(x,y) || fuzzy<fpt>::EQ(x,y)) ); -assert( fuzzy<fpt>::GE(x,y) == (fuzzy<fpt>::GT(x,y) || fuzzy<fpt>::EQ(x,y)) ); +assert( fuzzy<fp>::LE(x,y) == (fuzzy<fp>::LT(x,y) || fuzzy<fp>::EQ(x,y)) ); +assert( fuzzy<fp>::GE(x,y) == (fuzzy<fp>::GT(x,y) || fuzzy<fp>::EQ(x,y)) ); // @@ -172,23 +172,23 @@ assert( fuzzy<fpt>::GE(x,y) == (fuzzy<fpt>::GT(x,y) || fuzzy<fpt>::EQ(x,y)) ); switch (xy_relation) { case '<': - assert( fuzzy<fpt>::LT(x,y) == true ); - assert( fuzzy<fpt>::EQ(x,y) == false ); - assert( fuzzy<fpt>::GT(x,y) == false ); + assert( fuzzy<fp>::LT(x,y) == true ); + assert( fuzzy<fp>::EQ(x,y) == false ); + assert( fuzzy<fp>::GT(x,y) == false ); break; case '=': - assert( fuzzy<fpt>::LT(x,y) == false ); - assert( fuzzy<fpt>::EQ(x,y) == true ); - assert( fuzzy<fpt>::GT(x,y) == false ); + assert( fuzzy<fp>::LT(x,y) == false ); + assert( fuzzy<fp>::EQ(x,y) == true ); + assert( fuzzy<fp>::GT(x,y) == false ); break; case '>': - assert( fuzzy<fpt>::LT(x,y) == false ); - assert( fuzzy<fpt>::EQ(x,y) == false ); - assert( fuzzy<fpt>::GT(x,y) == true ); + assert( fuzzy<fp>::LT(x,y) == false ); + assert( fuzzy<fp>::EQ(x,y) == false ); + assert( fuzzy<fp>::GT(x,y) == true ); break; default: error_exit(PANIC_EXIT, -"***** check_binary<fpt>: bad xy_relation=(int)'%c'\n" +"***** check_binary<fp>: bad xy_relation=(int)'%c'\n" " (this should never happen!)\n" , int(xy_relation)); /*NOTREACHED*/ @@ -199,21 +199,21 @@ default: // // This function template tests the unary functions -// fuzzy<fpt>::is_integer() -// fuzzy<fpt>::floor() -// fuzzy<fpt>::ceiling() +// fuzzy<fp>::is_integer() +// fuzzy<fp>::floor() +// fuzzy<fp>::ceiling() // for a single argument. // -template <typename fpt> - void check_unary(fpt x, +template <typename fp> + void check_unary(fp x, // remaining arguments are the correct results of... - bool x_is_fuzzy_integer, // ... fuzzy<fpt>::is_integer(x) - int fuzzy_floor_of_x, // ... fuzzy<fpt>::floor(x) - int fuzzy_ceiling_of_x) // ... fuzzy<fpt>::ceiling(x) + bool x_is_fuzzy_integer, // ... fuzzy<fp>::is_integer(x) + int fuzzy_floor_of_x, // ... fuzzy<fp>::floor(x) + int fuzzy_ceiling_of_x) // ... fuzzy<fp>::ceiling(x) { -assert( fuzzy<fpt>::is_integer(x) == x_is_fuzzy_integer ); -assert( fuzzy<fpt>::floor(x) == fuzzy_floor_of_x ); -assert( fuzzy<fpt>::ceiling(x) == fuzzy_ceiling_of_x ); +assert( fuzzy<fp>::is_integer(x) == x_is_fuzzy_integer ); +assert( fuzzy<fp>::floor(x) == fuzzy_floor_of_x ); +assert( fuzzy<fp>::ceiling(x) == fuzzy_ceiling_of_x ); } //****************************************************************************** diff --git a/src/jtutil/test_round.cc b/src/jtutil/test_round.cc index 793c81d..ac0925e 100644 --- a/src/jtutil/test_round.cc +++ b/src/jtutil/test_round.cc @@ -1,4 +1,4 @@ -// test_round.cc -- test driver for round<fpt> and round<double> +// test_round.cc -- test driver for round<fp> and round<double> // $Id$ #include <stdio.h> @@ -21,7 +21,7 @@ int main(int argc, const char* const argv[]) // - // round<fpt>::to_integer() + // round<fp>::to_integer() // assert( round<double>::to_integer(d - 0.49) == i ); @@ -46,7 +46,7 @@ int main(int argc, const char* const argv[]) // - // round<fpt>::floor() + // round<fp>::floor() // assert( round<double>::floor(d - 0.49) == i-1 ); @@ -73,7 +73,7 @@ int main(int argc, const char* const argv[]) // - // round<fpt>::ceiling() + // round<fp>::ceiling() // assert( round<double>::ceiling(d - 0.49) == i ); diff --git a/src/jtutil/util.hh b/src/jtutil/util.hh index c07cb5e..5dd0b90 100644 --- a/src/jtutil/util.hh +++ b/src/jtutil/util.hh @@ -4,8 +4,8 @@ // jtutil::{min,max} - min/max templates // jtutil::abs - absolute value template // jtutil::pow* - raise floating point value to small-integer power -// fuzzy::<fpt> - fuzzy floating point comparisons and other operations -// round::<fpt> - floating point rounding +// fuzzy::<fp> - fuzzy floating point comparisons and other operations +// round::<fp> - floating point rounding // //****************************************************************************** @@ -36,28 +36,28 @@ template <typename num> // absolute value template // FIXME: this ought to be somewhere in the STL? // -template <typename fpt> - inline fpt abs(fpt x) { return (x > 0.0) ? x : -x; } +template <typename fp> + inline fp abs(fp x) { return (x > 0.0) ? x : -x; } // // These functions raise their arguments (presumably floating-point) // to various small-integer powers. // FIXME: do we ever use these? // -template <typename fpt> - inline fpt pow2(fpt x) { return x*x; } -template <typename fpt> - inline fpt pow3(fpt x) { return x*x*x; } -template <typename fpt> - inline fpt pow4(fpt x) { return pow2(pow2(x)); } -template <typename fpt> - inline fpt pow5(fpt x) { return x * pow4(x); } -template <typename fpt> - inline fpt pow6(fpt x) { return pow3(pow2(x)); } -template <typename fpt> - inline fpt pow7(fpt x) { return x * pow6(x); } -template <typename fpt> - inline fpt pow8(fpt x) { return pow2(pow2(pow2(x))); } +template <typename fp> + inline fp pow2(fp x) { return x*x; } +template <typename fp> + inline fp pow3(fp x) { return x*x*x; } +template <typename fp> + inline fp pow4(fp x) { return pow2(pow2(x)); } +template <typename fp> + inline fp pow5(fp x) { return x * pow4(x); } +template <typename fp> + inline fp pow6(fp x) { return pow3(pow2(x)); } +template <typename fp> + inline fp pow7(fp x) { return x * pow6(x); } +template <typename fp> + inline fp pow8(fp x) { return pow2(pow2(pow2(x))); } // // misc math stuff @@ -69,10 +69,10 @@ double arctan_xy(double x, double y); // more misc math stuff, valid only if <math.h> has been #included #ifdef PI // from "jt/stdc.h" // convert degrees <--> radians - template <typename fpt> - inline fpt degrees_of_radians(fpt radians) { return (180.0/PI)*radians; } - template <typename fpt> - inline fpt radians_of_degrees(fpt degrees) { return (PI/180.0)*degrees; } + template <typename fp> + inline fp degrees_of_radians(fp radians) { return (180.0/PI)*radians; } + template <typename fp> + inline fp radians_of_degrees(fp degrees) { return (PI/180.0)*degrees; } #endif }; // close namespace jtutil:: @@ -93,27 +93,27 @@ double arctan_xy(double x, double y); // than the individual members being conceptually-unrelated templates // ... moreover, we need the *data* member (template) tolerance , and // it seems C++ doesn't grok data templates which aren't in a class -template <typename fpt> +template <typename fp> class fuzzy { public: // comparison tolerance // ... must be explicitly initialized when instantiating - // for a new <fpt> type, see "fuzzy.cc" for details/examples + // for a new <fp> type, see "fuzzy.cc" for details/examples // ... may be modified by user code if needed - static fpt tolerance; + static fp tolerance; // fuzzy commparisons - static bool EQ(fpt x, fpt y); - static bool NE(fpt x, fpt y) { return ! EQ(x,y); } - static bool LT(fpt x, fpt y) { return EQ(x,y) ? false : (x < y); } - static bool LE(fpt x, fpt y) { return EQ(x,y) ? true : (x < y); } - static bool GT(fpt x, fpt y) { return EQ(x,y) ? false : (x > y); } - static bool GE(fpt x, fpt y) { return EQ(x,y) ? true : (x > y); } - - static bool is_integer(fpt x); // is x fuzzily an integer? - static int floor(fpt x); // round x fuzzily down to integer - static int ceiling(fpt x); // round x fuzzily up to integer + static bool EQ(fp x, fp y); + static bool NE(fp x, fp y) { return ! EQ(x,y); } + static bool LT(fp x, fp y) { return EQ(x,y) ? false : (x < y); } + static bool LE(fp x, fp y) { return EQ(x,y) ? true : (x < y); } + static bool GT(fp x, fp y) { return EQ(x,y) ? false : (x > y); } + static bool GE(fp x, fp y) { return EQ(x,y) ? true : (x > y); } + + 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 }; //****************************************************************************** @@ -127,12 +127,12 @@ public: // ... it's a class, not a namespace, because we want to express the // semantics that the entire class is a single template, rather // than the individual members being conceptually-unrelated templates -template <typename fpt> +template <typename fp> class round { public: - static int to_integer(fpt x); // round to nearest integer + static int to_integer(fp x); // round to nearest integer - static int floor(fpt x); // round down to integer - static int ceiling(fpt x); // round up to integer + static int floor(fp x); // round down to integer + static int ceiling(fp x); // round up to integer }; |