Skip to content

Commit

Permalink
add normalize function (apache#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
rui-mo authored and zhouyuan committed Jun 8, 2021
1 parent 918c3ee commit 5365cb1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cpp/src/gandiva/function_registry_arithmetic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ std::vector<NativeFunction> 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),
Expand Down
18 changes: 18 additions & 0 deletions cpp/src/gandiva/precompiled/arithmetic_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit 5365cb1

Please sign in to comment.