Skip to content

Commit 360c5ef

Browse files
philo-hezhztheplayer
authored andcommitted
Add two math operations: floor & ceil (apache#72)
* Inital commit * Add ceil function
1 parent ca2d251 commit 360c5ef

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

cpp/src/gandiva/function_registry_arithmetic.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ std::vector<NativeFunction> GetArithmeticFunctionRegistry() {
173173
// normalize for nan and zero
174174
UNARY_SAFE_NULL_IF_NULL(normalize, {}, float32, float32),
175175
UNARY_SAFE_NULL_IF_NULL(normalize, {}, float64, float64),
176+
// floor
177+
UNARY_SAFE_NULL_IF_NULL(floor, {}, float64, int64),
178+
UNARY_SAFE_NULL_IF_NULL(floor, {}, int64, int64),
179+
// ceil
180+
UNARY_SAFE_NULL_IF_NULL(ceil, {}, float64, int64),
181+
UNARY_SAFE_NULL_IF_NULL(ceil, {}, int64, int64),
176182
// bitwise functions
177183
BINARY_GENERIC_SAFE_NULL_IF_NULL(shift_left, {}, int32, int32, int32),
178184
BINARY_GENERIC_SAFE_NULL_IF_NULL(shift_left, {}, int64, int32, int64),

cpp/src/gandiva/precompiled/arithmetic_ops.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,30 @@ NORMALIZE(float32, float32)
242242

243243
#undef NORMALIZE
244244

245+
// floor
246+
#define FLOOR(IN_TYPE, OUT_TYPE) \
247+
FORCE_INLINE \
248+
gdv_##OUT_TYPE floor_##IN_TYPE(gdv_##IN_TYPE in) { \
249+
return static_cast<gdv_##OUT_TYPE>(std::floor(in)); \
250+
}
251+
252+
FLOOR(float64, int64)
253+
FLOOR(int64, int64)
254+
255+
#undef FLOOR
256+
257+
// ceil
258+
#define CEIL(IN_TYPE, OUT_TYPE) \
259+
FORCE_INLINE \
260+
gdv_##OUT_TYPE ceil_##IN_TYPE(gdv_##IN_TYPE in) { \
261+
return static_cast<gdv_##OUT_TYPE>(std::ceil(in)); \
262+
}
263+
264+
CEIL(float64, int64)
265+
CEIL(int64, int64)
266+
267+
#undef CEIL
268+
245269
// cast fns : takes one param type, returns another type.
246270
#define CAST_UNARY(NAME, IN_TYPE, OUT_TYPE) \
247271
FORCE_INLINE \

0 commit comments

Comments
 (0)