diff --git a/cpp/src/gandiva/function_registry_arithmetic.cc b/cpp/src/gandiva/function_registry_arithmetic.cc index e578c5205b6ed..dd960f84280c2 100644 --- a/cpp/src/gandiva/function_registry_arithmetic.cc +++ b/cpp/src/gandiva/function_registry_arithmetic.cc @@ -111,6 +111,9 @@ std::vector GetArithmeticFunctionRegistry() { UNARY_SAFE_NULL_IF_NULL(round, {}, int64, int64), BINARY_GENERIC_SAFE_NULL_IF_NULL(round, {}, int32, int32, int32), BINARY_GENERIC_SAFE_NULL_IF_NULL(round, {}, int64, int32, int64), + // normalize for nan and zero + UNARY_SAFE_NULL_IF_NULL(normalize, {}, float32, float32), + UNARY_SAFE_NULL_IF_NULL(normalize, {}, float64, float64), // bitwise functions BINARY_GENERIC_SAFE_NULL_IF_NULL(shift_left, {}, int32, int32, int32), BINARY_GENERIC_SAFE_NULL_IF_NULL(shift_left, {}, int64, int32, int64), diff --git a/cpp/src/gandiva/precompiled/arithmetic_ops.cc b/cpp/src/gandiva/precompiled/arithmetic_ops.cc index 4a0ad00cb4a75..988c507db823b 100644 --- a/cpp/src/gandiva/precompiled/arithmetic_ops.cc +++ b/cpp/src/gandiva/precompiled/arithmetic_ops.cc @@ -139,6 +139,24 @@ NUMERIC_DATE_TYPES(BINARY_RELATIONAL_NAN, greater_than_or_equal_to_with_nan, >=) #undef BINARY_RELATIONAL_NAN +// normalize +#define NORMALIZE(IN_TYPE, OUT_TYPE) \ + FORCE_INLINE \ + gdv_##OUT_TYPE normalize_##IN_TYPE(gdv_##IN_TYPE in) { \ + if (isnan(in)) { \ + return 0.0 / 0.0; \ + } else if (in < 0 && std::abs(in) < 0.0000001) { \ + return 0.0; \ + } else { \ + return in; \ + } \ + } + +NORMALIZE(float64, float64) +NORMALIZE(float32, float32) + +#undef NORMALIZE + // cast fns : takes one param type, returns another type. #define CAST_UNARY(NAME, IN_TYPE, OUT_TYPE) \ FORCE_INLINE \