diff --git a/modules/cudaarithm/src/cuda/math.cu b/modules/cudaarithm/src/cuda/math.cu index 41d762f6a6..b885319659 100644 --- a/modules/cudaarithm/src/cuda/math.cu +++ b/modules/cudaarithm/src/cuda/math.cu @@ -278,20 +278,12 @@ namespace { template::is_signed> struct PowOp : unary_function { - float power; + typedef typename LargerType::type LargerType; + LargerType power; __device__ __forceinline__ T operator()(T e) const { - return cudev::saturate_cast(__powf((float)e, power)); - } - }; - template struct PowOp : unary_function - { - float power; - - __device__ __forceinline__ T operator()(T e) const - { - T res = cudev::saturate_cast(__powf((float)e, power)); + T res = cudev::saturate_cast(__powf(e < 0 ? -e : e, power)); if ((e < 0) && (1 & static_cast(power))) res *= -1; @@ -299,22 +291,15 @@ namespace return res; } }; - template<> struct PowOp : unary_function - { - float power; - __device__ __forceinline__ float operator()(float e) const - { - return __powf(::fabs(e), power); - } - }; - template<> struct PowOp : unary_function + template struct PowOp : unary_function { - double power; + typedef typename LargerType::type LargerType; + LargerType power; - __device__ __forceinline__ double operator()(double e) const + __device__ __forceinline__ T operator()(T e) const { - return ::pow(::fabs(e), power); + return cudev::saturate_cast(__powf(e, power)); } };