Skip to content

Commit

Permalink
Add two math operations: floor & ceil (#72)
Browse files Browse the repository at this point in the history
* Inital commit

* Add ceil function
  • Loading branch information
PHILO-HE authored Jan 7, 2022
1 parent 1162e63 commit c2f31f5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cpp/src/gandiva/function_registry_arithmetic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ std::vector<NativeFunction> GetArithmeticFunctionRegistry() {
// normalize for nan and zero
UNARY_SAFE_NULL_IF_NULL(normalize, {}, float32, float32),
UNARY_SAFE_NULL_IF_NULL(normalize, {}, float64, float64),
// floor
UNARY_SAFE_NULL_IF_NULL(floor, {}, float64, int64),
UNARY_SAFE_NULL_IF_NULL(floor, {}, int64, int64),
// ceil
UNARY_SAFE_NULL_IF_NULL(ceil, {}, float64, int64),
UNARY_SAFE_NULL_IF_NULL(ceil, {}, int64, int64),
// 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
24 changes: 24 additions & 0 deletions cpp/src/gandiva/precompiled/arithmetic_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,30 @@ NORMALIZE(float32, float32)

#undef NORMALIZE

// floor
#define FLOOR(IN_TYPE, OUT_TYPE) \
FORCE_INLINE \
gdv_##OUT_TYPE floor_##IN_TYPE(gdv_##IN_TYPE in) { \
return static_cast<gdv_##OUT_TYPE>(std::floor(in)); \
}

FLOOR(float64, int64)
FLOOR(int64, int64)

#undef FLOOR

// ceil
#define CEIL(IN_TYPE, OUT_TYPE) \
FORCE_INLINE \
gdv_##OUT_TYPE ceil_##IN_TYPE(gdv_##IN_TYPE in) { \
return static_cast<gdv_##OUT_TYPE>(std::ceil(in)); \
}

CEIL(float64, int64)
CEIL(int64, int64)

#undef CEIL

// 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 c2f31f5

Please sign in to comment.