From c2f31f528be5d7b588f19bbb56383d9e0fd89374 Mon Sep 17 00:00:00 2001 From: PHILO-HE Date: Fri, 7 Jan 2022 10:08:37 +0800 Subject: [PATCH] Add two math operations: floor & ceil (#72) * Inital commit * Add ceil function --- .../gandiva/function_registry_arithmetic.cc | 6 +++++ cpp/src/gandiva/precompiled/arithmetic_ops.cc | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/cpp/src/gandiva/function_registry_arithmetic.cc b/cpp/src/gandiva/function_registry_arithmetic.cc index b9c762298cb42..af07e353152a1 100644 --- a/cpp/src/gandiva/function_registry_arithmetic.cc +++ b/cpp/src/gandiva/function_registry_arithmetic.cc @@ -115,6 +115,12 @@ std::vector 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), diff --git a/cpp/src/gandiva/precompiled/arithmetic_ops.cc b/cpp/src/gandiva/precompiled/arithmetic_ops.cc index 7d7eed6defc85..270a9159ea926 100644 --- a/cpp/src/gandiva/precompiled/arithmetic_ops.cc +++ b/cpp/src/gandiva/precompiled/arithmetic_ops.cc @@ -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(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(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 \