sql_utils/common/multiprecision_int.cc (39 lines of code) (raw):
/*
* Copyright 2023 Google LLC
*
* Licensed 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.
*/
#include "sql_utils/common/multiprecision_int.h"
#include <cstdint>
#include <type_traits>
namespace bigquery_ml_utils {
namespace multiprecision_int_impl {
namespace {
template <uint64_t power>
uint64_t DividePower10(VarUintRef<64>& var_int, uint64_t& remainder) {
remainder = var_int.DivMod(std::integral_constant<uint64_t, power>());
return power;
}
template <>
uint64_t DividePower10<1>(VarUintRef<64>& var_int, uint64_t& remainder) {
return 1;
}
} // namespace
uint64_t (*kVarUintDivModPow10[])(VarUintRef<64>&, uint64_t&) = {
&DividePower10<1>,
&DividePower10<10>,
&DividePower10<100>,
&DividePower10<1000>,
&DividePower10<10000>,
&DividePower10<100000>,
&DividePower10<1000000>,
&DividePower10<10000000>,
&DividePower10<100000000>,
&DividePower10<1000000000>,
&DividePower10<10000000000>,
&DividePower10<100000000000>,
&DividePower10<1000000000000>,
&DividePower10<10000000000000>,
&DividePower10<100000000000000>,
&DividePower10<1000000000000000>,
&DividePower10<10000000000000000>,
&DividePower10<100000000000000000>,
&DividePower10<1000000000000000000>,
&DividePower10<10000000000000000000ULL>};
} // namespace multiprecision_int_impl
} // namespace bigquery_ml_utils