diff options
author | Erik Schnetter <schnetter@gmail.com> | 2013-04-22 19:21:57 -0400 |
---|---|---|
committer | Erik Schnetter <schnetter@gmail.com> | 2013-04-22 19:21:57 -0400 |
commit | 0fe7c850e2f3a4166a0dc57af5ed11159a154ab6 (patch) | |
tree | 9b3b2e6f6360d0d9822f30c5a311a22440e95a89 /vec_pseudo.h | |
parent | 750e941a0ef3bf956e665b5ea8ef948cf7ba3506 (diff) | |
download | vecmathlib-0fe7c850e2f3a4166a0dc57af5ed11159a154ab6.zip vecmathlib-0fe7c850e2f3a4166a0dc57af5ed11159a154ab6.tar.gz |
Use -1 for true in vec_pseudo
Diffstat (limited to 'vec_pseudo.h')
-rw-r--r-- | vec_pseudo.h | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/vec_pseudo.h b/vec_pseudo.h index ba70d2e..dfad3fc 100644 --- a/vec_pseudo.h +++ b/vec_pseudo.h @@ -31,7 +31,7 @@ namespace vecmathlib { static int const size = N; typedef bool scalar_t; - typedef bool bvector_t[size]; + typedef uint_t bvector_t[size]; typedef boolpseudovec boolvec_t; typedef intpseudovec<real_t, size> intvec_t; @@ -56,11 +56,11 @@ namespace vecmathlib { // be passed in registers // boolpseudovec(boolpseudovec const& x): v(x.v) {} // boolpseudovec& operator=(boolpseudovec const& x) { return v=x.v, *this; } - boolpseudovec(bool a) { for (int d=0; d<size; ++d) v[d]=a; } - boolpseudovec(bool const* as) { for (int d=0; d<size; ++d) v[d]=as[d]; } + boolpseudovec(bool a) { for (int d=0; d<size; ++d) v[d]=-a; } + boolpseudovec(bool const* as) { for (int d=0; d<size; ++d) v[d]=-as[d]; } bool operator[](int n) const { return v[n]; } - boolpseudovec& set_elt(int n, bool a) { return v[n]=a, *this; } + boolpseudovec& set_elt(int n, bool a) { return v[n]=-a, *this; } @@ -171,12 +171,17 @@ namespace vecmathlib { - boolvec_t as_bool() const { return convert_bool(); } + boolvec_t as_bool() const + { + boolvec_t res; + for (int d=0; d<size; ++d) res.v[d]=v[d]; + return res; + } boolvec_t convert_bool() const { // Result: convert_bool(0)=false, convert_bool(else)=true boolvec_t res; - for (int d=0; d<size; ++d) res.v[d]=v[d]; + for (int d=0; d<size; ++d) res.set_elt(d, v[d]); return res; } realvec_t as_float() const; // defined after realpseudovec @@ -351,37 +356,37 @@ namespace vecmathlib { boolvec_t operator==(intpseudovec const& x) const { boolvec_t res; - for (int d=0; d<size; ++d) res.v[d] = v[d] == x.v[d]; + for (int d=0; d<size; ++d) res.set_elt(d, v[d] == x.v[d]); return res; } boolvec_t operator!=(intpseudovec const& x) const { boolvec_t res; - for (int d=0; d<size; ++d) res.v[d] = v[d] != x.v[d]; + for (int d=0; d<size; ++d) res.set_elt(d, v[d] != x.v[d]); return res; } boolvec_t operator<(intpseudovec const& x) const { boolvec_t res; - for (int d=0; d<size; ++d) res.v[d] = v[d] < x.v[d]; + for (int d=0; d<size; ++d) res.set_elt(d, v[d] < x.v[d]); return res; } boolvec_t operator<=(intpseudovec const& x) const { boolvec_t res; - for (int d=0; d<size; ++d) res.v[d] = v[d] <= x.v[d]; + for (int d=0; d<size; ++d) res.set_elt(d, v[d] <= x.v[d]); return res; } boolvec_t operator>(intpseudovec const& x) const { boolvec_t res; - for (int d=0; d<size; ++d) res.v[d] = v[d] > x.v[d]; + for (int d=0; d<size; ++d) res.set_elt(d, v[d] > x.v[d]); return res; } boolvec_t operator>=(intpseudovec const& x) const { boolvec_t res; - for (int d=0; d<size; ++d) res.v[d] = v[d] >= x.v[d]; + for (int d=0; d<size; ++d) res.set_elt(d, v[d] >= x.v[d]); return res; } }; @@ -418,38 +423,38 @@ namespace vecmathlib { boolvec_t mapb(bool f(real_t)) const { boolvec_t res; - for (int d=0; d<size; ++d) res.v[d] = f(v[d]); + for (int d=0; d<size; ++d) res.set_elt(d, f(v[d])); return res; } intvec_t map(int_t f(real_t)) const { intvec_t res; - for (int d=0; d<size; ++d) res.v[d] = f(v[d]); + for (int d=0; d<size; ++d) res.set_elt(d, f(v[d])); return res; } realvec_t map(real_t f(real_t)) const { realvec_t res; - for (int d=0; d<size; ++d) res.v[d] = f(v[d]); + for (int d=0; d<size; ++d) res.set_elt(d, f(v[d])); return res; } realvec_t map(real_t f(real_t, int_t), intvec_t x) const { realvec_t res; - for (int d=0; d<size; ++d) res.v[d] = f(v[d], x.v[d]); + for (int d=0; d<size; ++d) res.set_elt(d, f(v[d], x.v[d])); return res; } realvec_t map(real_t f(real_t, real_t), realvec_t x) const { realvec_t res; - for (int d=0; d<size; ++d) res.v[d] = f(v[d], x.v[d]); + for (int d=0; d<size; ++d) res.set_elt(d, f(v[d], x.v[d])); return res; } realvec_t map(real_t f(real_t, real_t, real_t), realvec_t x, realvec_t y) const { realvec_t res; - for (int d=0; d<size; ++d) res.v[d] = f(v[d], x.v[d], y.v[d]); + for (int d=0; d<size; ++d) res.set_elt(d, f(v[d], x.v[d], y.v[d])); return res; } public: @@ -631,37 +636,37 @@ namespace vecmathlib { boolvec_t operator==(realpseudovec const& x) const { boolvec_t res; - for (int d=0; d<size; ++d) res.v[d] = v[d] == x.v[d]; + for (int d=0; d<size; ++d) res.set_elt(d, v[d] == x.v[d]); return res; } boolvec_t operator!=(realpseudovec const& x) const { boolvec_t res; - for (int d=0; d<size; ++d) res.v[d] = v[d] != x.v[d]; + for (int d=0; d<size; ++d) res.set_elt(d, v[d] != x.v[d]); return res; } boolvec_t operator<(realpseudovec const& x) const { boolvec_t res; - for (int d=0; d<size; ++d) res.v[d] = v[d] < x.v[d]; + for (int d=0; d<size; ++d) res.set_elt(d, v[d] < x.v[d]); return res; } boolvec_t operator<=(realpseudovec const& x) const { boolvec_t res; - for (int d=0; d<size; ++d) res.v[d] = v[d] <= x.v[d]; + for (int d=0; d<size; ++d) res.set_elt(d, v[d] <= x.v[d]); return res; } boolvec_t operator>(realpseudovec const& x) const { boolvec_t res; - for (int d=0; d<size; ++d) res.v[d] = v[d] > x.v[d]; + for (int d=0; d<size; ++d) res.set_elt(d, v[d] > x.v[d]); return res; } boolvec_t operator>=(realpseudovec const& x) const { boolvec_t res; - for (int d=0; d<size; ++d) res.v[d] = v[d] >= x.v[d]; + for (int d=0; d<size; ++d) res.set_elt(d, v[d] >= x.v[d]); return res; } |