commit 848e4b6de431215f63d0ac9520ecb254d5625ebb
parent d37d4210057ce994c3ce2691fc91451fced8a584
Author: Dan Levin <[email protected]>
Date: Thu, 16 Nov 2017 23:02:31 +0300
Fix clamp and pow functions
Diffstat:
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/include/kfr/base/clamp.hpp b/include/kfr/base/clamp.hpp
@@ -33,6 +33,12 @@ namespace kfr
namespace intrinsics
{
+template <typename T>
+KFR_SINTRIN T clamp(const T& x, const T& lo, const T& hi)
+{
+ return max(min(x, hi), lo);
+}
+
template <typename T, size_t N>
KFR_SINTRIN vec<T, N> clamp(const vec<T, N>& x, const vec<T, N>& lo, const vec<T, N>& hi)
{
diff --git a/include/kfr/base/log_exp.hpp b/include/kfr/base/log_exp.hpp
@@ -239,7 +239,7 @@ KFR_SINTRIN vec<T, N> pow(const vec<T, N>& a, const vec<T, N>& b)
const vec<T, N> t = exp(b * log(abs(a)));
const mask<T, N> isint = floor(b) == b;
const mask<T, N> iseven = (cast<itype<T>>(b) & 1) == 0;
- return select(a > T(), t, select(a == T(), T(1),
+ return select(a > T(), t, select(a == T(), T(),
select(isint, select(iseven, t, -t), broadcast<N>(constants<T>::qnan))));
}