diff options
author | Erik Schnetter <schnetter@gmail.com> | 2013-02-14 16:47:08 -0500 |
---|---|---|
committer | Erik Schnetter <schnetter@gmail.com> | 2013-02-14 16:47:08 -0500 |
commit | 16eba4ea2d067f727f64de48f0cd18709132502c (patch) | |
tree | b9fd3cf53894965109f28d77a784db380346b922 /mathfuncs_convert.h | |
parent | ac6a002775fed4bf38a3d6e2baa19f053f4e36ea (diff) | |
download | vecmathlib-16eba4ea2d067f727f64de48f0cd18709132502c.zip vecmathlib-16eba4ea2d067f727f64de48f0cd18709132502c.tar.gz |
Correct ceil() and floor()
Diffstat (limited to 'mathfuncs_convert.h')
-rw-r--r-- | mathfuncs_convert.h | 10 |
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 |