summaryrefslogtreecommitdiffstats
path: root/mathfuncs_convert.h
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@gmail.com>2013-02-14 16:47:08 -0500
committerErik Schnetter <schnetter@gmail.com>2013-02-14 16:47:08 -0500
commit16eba4ea2d067f727f64de48f0cd18709132502c (patch)
treeb9fd3cf53894965109f28d77a784db380346b922 /mathfuncs_convert.h
parentac6a002775fed4bf38a3d6e2baa19f053f4e36ea (diff)
downloadvecmathlib-16eba4ea2d067f727f64de48f0cd18709132502c.zip
vecmathlib-16eba4ea2d067f727f64de48f0cd18709132502c.tar.gz
Correct ceil() and floor()
Diffstat (limited to 'mathfuncs_convert.h')
-rw-r--r--mathfuncs_convert.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/mathfuncs_convert.h b/mathfuncs_convert.h
index 6645f45..4a2a7ff 100644
--- a/mathfuncs_convert.h
+++ b/mathfuncs_convert.h
@@ -112,15 +112,17 @@ namespace vecmathlib {
template<typename realvec_t>
realvec_t mathfuncs<realvec_t>::vml_ceil(realvec_t x)
{
- real_t offset = R(0.5) - std::scalbn(fabs(x), -FP::mantissa_bits);
- return round(x + RV(offset));
+ boolvec_t iszero = x == RV(0.0);
+ realvec_t offset = RV(0.5) - scalbn(fabs(x), I(-FP::mantissa_bits));
+ return ifthen(iszero, x, round(x + offset));
}
template<typename realvec_t>
realvec_t mathfuncs<realvec_t>::vml_floor(realvec_t x)
{
- real_t offset = R(0.5) - std::scalbn(fabs(x), -FP::mantissa_bits);
- return round(x - RV(offset));
+ boolvec_t iszero = x == RV(0.0);
+ realvec_t offset = RV(0.5) - scalbn(fabs(x), I(-FP::mantissa_bits));
+ return ifthen(iszero, x, round(x - offset));
}
}; // namespace vecmathlib
OpenPOWER on IntegriCloud