Skip to content

Commit

Permalink
add truncate
Browse files Browse the repository at this point in the history
  • Loading branch information
zjbpaul1317 committed Oct 29, 2024
1 parent 85de59f commit 5ab7e12
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/function/scalar/truncate.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module;

#include <cmath>
#include <utility>

Expand All @@ -18,7 +20,7 @@ namespace infinity {

struct TruncateFunction {
template <typename LeftType, typename RightType, typename OutputType>
static inline bool Run(LeftType value, RightType decimals, OutputType &result) {
static inline void Run(LeftType value, RightType decimals, OutputType &result) {
if (decimals > 0) {
double scale = pow(10.0, decimals);
result = static_cast<OutputType>(std::trunc(value * scale) / scale);
Expand All @@ -28,7 +30,6 @@ struct TruncateFunction {
double scale = pow(10.0, -decimals);
result = static_cast<OutputType>(std::trunc(value / scale) * scale);
}
return true;
}
};

Expand Down

0 comments on commit 5ab7e12

Please sign in to comment.