Skip to content

Commit

Permalink
Merge pull request apache#46 from zhouyuan/wip_abs
Browse files Browse the repository at this point in the history
[C++][Gandiva] Adding abs function
  • Loading branch information
zhouyuan authored May 18, 2020
2 parents 7c0bf06 + 43e48bd commit 7a60602
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cpp/src/gandiva/function_registry_math_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ std::vector<NativeFunction> GetMathOpsFunctionRegistry() {
BINARY_SAFE_NULL_NEVER_BOOL_FN(is_distinct_from, {}),
BINARY_SAFE_NULL_NEVER_BOOL_FN(is_not_distinct_from, {}),

UNARY_SAFE_NULL_IF_NULL(abs, {}, int32, uint32),
UNARY_SAFE_NULL_IF_NULL(abs, {}, int64, uint64),
UNARY_SAFE_NULL_IF_NULL(abs, {}, float32, float32),
UNARY_SAFE_NULL_IF_NULL(abs, {}, float64, float64),

// decimal functions
UNARY_SAFE_NULL_IF_NULL(abs, {}, decimal128, decimal128),
UNARY_SAFE_NULL_IF_NULL(ceil, {}, decimal128, decimal128),
Expand Down
18 changes: 18 additions & 0 deletions cpp/src/gandiva/precompiled/extended_math_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ ENUMERIC_TYPES_UNARY(LOG, float64)

ENUMERIC_TYPES_UNARY(LOG10, float64)

// abs
#define ABS_TYPES_UNARY(IN_TYPE, OUT_TYPE) \
FORCE_INLINE \
gdv_##OUT_TYPE abs_##IN_TYPE(gdv_##IN_TYPE in) { \
return static_cast<gdv_##OUT_TYPE>(abs((in))); \
}

#define ABS_FTYPES_UNARY(IN_TYPE, OUT_TYPE) \
FORCE_INLINE \
gdv_##OUT_TYPE abs_##IN_TYPE(gdv_##IN_TYPE in) { \
return static_cast<gdv_##OUT_TYPE>(fabs((in))); \
}

ABS_TYPES_UNARY(int32, uint32)
ABS_TYPES_UNARY(int64, uint64)
ABS_FTYPES_UNARY(float32, float32)
ABS_FTYPES_UNARY(float64, float64)

FORCE_INLINE
void set_error_for_logbase(int64_t execution_context, double base) {
char const* prefix = "divide by zero error with log of base";
Expand Down
5 changes: 5 additions & 0 deletions cpp/src/gandiva/precompiled/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ gdv_float64 log10_int64(gdv_int64);
gdv_float64 log10_float32(gdv_float32);
gdv_float64 log10_float64(gdv_float64);

gdv_uint32 abs_int32(gdv_int32);
gdv_uint64 abs_int64(gdv_int64);
gdv_float32 abs_float32(gdv_float32);
gdv_float64 abs_float64(gdv_float64);

gdv_float64 power_float64_float64(gdv_float64, gdv_float64);

gdv_float64 log_int32_int32(gdv_int64 context, gdv_int32 base, gdv_int32 value);
Expand Down

0 comments on commit 7a60602

Please sign in to comment.