summaryrefslogtreecommitdiffstats
path: root/mathfuncs_convert.h
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@gmail.com>2013-06-09 00:16:29 -0400
committerErik Schnetter <schnetter@gmail.com>2013-06-09 00:16:29 -0400
commit7e8e3bee8f9ae74e9d9cd9b4601f215c229335a5 (patch)
treebc86580fe4b245b315db74f4f8c5ce493f136bfb /mathfuncs_convert.h
parent039eafa275852004c3483ecee323527f90e6ac81 (diff)
downloadvecmathlib-7e8e3bee8f9ae74e9d9cd9b4601f215c229335a5.zip
vecmathlib-7e8e3bee8f9ae74e9d9cd9b4601f215c229335a5.tar.gz
Implement nextafter
Diffstat (limited to 'mathfuncs_convert.h')
-rw-r--r--mathfuncs_convert.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/mathfuncs_convert.h b/mathfuncs_convert.h
index d11c700..841ded4 100644
--- a/mathfuncs_convert.h
+++ b/mathfuncs_convert.h
@@ -172,6 +172,23 @@ namespace vecmathlib {
return r;
}
+ // Next machine representable number from x in direction y
+ template<typename realvec_t>
+ realvec_t mathfuncs<realvec_t>::vml_nextafter(realvec_t x, realvec_t y)
+ {
+ realvec_t dir = y - x;
+ realvec_t offset = ldexp(RV(FP::epsilon()), ilogb(x));
+ offset = copysign(offset, dir);
+ offset = ifthen(convert_bool(as_int(x) & IV(FP::mantissa_mask)) ||
+ signbit(x) == signbit(offset),
+ offset,
+ offset * RV(0.5));
+ realvec_t r = x + offset;
+ real_t smallest_pos = std::ldexp(FP::min(), -FP::mantissa_bits);
+ return ifthen(dir==RV(0.0), y,
+ ifthen(x==RV(0.0), copysign(RV(smallest_pos), dir), r));
+ }
+
}; // namespace vecmathlib
#endif // #ifndef MATHFUNCS_CONVERT_H
OpenPOWER on IntegriCloud