You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/12/12 02:58:49 UTC

[GitHub] [doris] HappenLee commented on a diff in pull request #14946: [function](round) compute accurate round value by decimal

HappenLee commented on code in PR #14946:
URL: https://github.com/apache/doris/pull/14946#discussion_r1045367400


##########
be/src/vec/functions/round.h:
##########
@@ -0,0 +1,555 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+// This file is copied from
+// https://github.com/ClickHouse/ClickHouse/blob/master/src/Functions/FunctionRound.h
+// and modified by Doris
+
+#pragma once
+
+#ifdef __SSE4_1__
+#include <smmintrin.h>
+#else
+#include <fenv.h>
+#endif
+
+#include "vec/columns/column.h"
+#include "vec/columns/column_decimal.h"
+#include "vec/data_types/data_type_decimal.h"
+#include "vec/data_types/data_type_number.h"
+
+namespace doris::vectorized {
+
+enum class ScaleMode {
+    Positive, // round to a number with N decimal places after the decimal point
+    Negative, // round to an integer with N zero characters
+    Zero,     // round to an integer
+};
+
+enum class RoundingMode {
+#ifdef __SSE4_1__
+    Round = _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC,
+    Floor = _MM_FROUND_TO_NEG_INF | _MM_FROUND_NO_EXC,
+    Ceil = _MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC,
+    Trunc = _MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC,
+#else
+    Round = 8, /// Values are correspond to above just in case.
+    Floor = 9,
+    Ceil = 10,
+    Trunc = 11,
+#endif
+};
+
+enum class TieBreakingMode {
+    Auto,    // use banker's rounding for floating point numbers, round up otherwise
+    Bankers, // use banker's rounding
+};
+
+template <typename T, RoundingMode rounding_mode, ScaleMode scale_mode,
+          TieBreakingMode tie_breaking_mode>
+struct IntegerRoundingComputation {
+    static const size_t data_count = 1;
+
+    static size_t prepare(size_t scale) { return scale; }
+
+    /// Integer overflow is Ok.
+    static ALWAYS_INLINE T computeImpl(T x, T scale) {

Review Comment:
   `compute_impl`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org