Skip to content

Commit 32568a3

Browse files
rui-mozhztheplayer
authored andcommitted
add normalize function (#11)
1 parent 7364557 commit 32568a3

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

cpp/src/gandiva/function_registry_arithmetic.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ std::vector<NativeFunction> GetArithmeticFunctionRegistry() {
111111
UNARY_SAFE_NULL_IF_NULL(round, {}, int64, int64),
112112
BINARY_GENERIC_SAFE_NULL_IF_NULL(round, {}, int32, int32, int32),
113113
BINARY_GENERIC_SAFE_NULL_IF_NULL(round, {}, int64, int32, int64),
114+
// normalize for nan and zero
115+
UNARY_SAFE_NULL_IF_NULL(normalize, {}, float32, float32),
116+
UNARY_SAFE_NULL_IF_NULL(normalize, {}, float64, float64),
114117
// bitwise functions
115118
BINARY_GENERIC_SAFE_NULL_IF_NULL(shift_left, {}, int32, int32, int32),
116119
BINARY_GENERIC_SAFE_NULL_IF_NULL(shift_left, {}, int64, int32, int64),

cpp/src/gandiva/precompiled/arithmetic_ops.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,24 @@ NUMERIC_DATE_TYPES(BINARY_RELATIONAL_NAN, greater_than_or_equal_to_with_nan, >=)
139139

140140
#undef BINARY_RELATIONAL_NAN
141141

142+
// normalize
143+
#define NORMALIZE(IN_TYPE, OUT_TYPE) \
144+
FORCE_INLINE \
145+
gdv_##OUT_TYPE normalize_##IN_TYPE(gdv_##IN_TYPE in) { \
146+
if (isnan(in)) { \
147+
return 0.0 / 0.0; \
148+
} else if (in < 0 && std::abs(in) < 0.0000001) { \
149+
return 0.0; \
150+
} else { \
151+
return in; \
152+
} \
153+
}
154+
155+
NORMALIZE(float64, float64)
156+
NORMALIZE(float32, float32)
157+
158+
#undef NORMALIZE
159+
142160
// cast fns : takes one param type, returns another type.
143161
#define CAST_UNARY(NAME, IN_TYPE, OUT_TYPE) \
144162
FORCE_INLINE \

0 commit comments

Comments
 (0)