github.com/matrixorigin/matrixone@v1.2.0/pkg/vectorize/floor/floor.go (about) 1 // Copyright 2021 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package floor 16 17 /* floor package provides floor function for all numeric types(uint8, uint16, uint32, uint64, int8, int16, int32, int64, float32, float64). 18 Floor returns the largest round number that is less than or equal to x. 19 example: 20 floor(12, -1) ----> 10 21 floor(12) ----> 12 22 floor(-12, -1) ----> -20 23 floor(-12, 1) ----> -12 24 floor(12.345) ----> 12 25 floor(12.345, 1) ----> 12.3 26 floor(-12.345, 1) ----> -12.4 27 floor(-12.345, -1) ----> -20 28 floor(-12.345) ----> -13 29 floor function takes one or two parameters as its argument, and the second argument must be a constant. 30 floor(x, N) 31 floor(x) == floor(x, 0) 32 N < 0, N zeroes in front of decimal point 33 N >= 0, floor to the Nth placeholder after decimal point 34 */ 35 36 import ( 37 "math" 38 ) 39 40 var MaxUint64digits = numOfDigits(math.MaxUint64) // 20 41 var MaxInt64digits = numOfDigits(math.MaxInt64) // 19 42 43 func numOfDigits(value uint64) int64 { 44 digits := int64(0) 45 for value > 0 { 46 value /= 10 47 digits++ 48 } 49 return digits 50 } 51 52 // ScaleTable is a lookup array for digits 53 var ScaleTable = [...]uint64{ 54 1, 55 10, 56 100, 57 1000, 58 10000, 59 100000, 60 1000000, 61 10000000, 62 100000000, 63 1000000000, 64 10000000000, 65 100000000000, 66 1000000000000, 67 10000000000000, 68 100000000000000, 69 1000000000000000, 70 10000000000000000, 71 100000000000000000, 72 1000000000000000000, 73 10000000000000000000, // 1 followed by 19 zeros, maxUint64 number has 20 digits, so the max scale is 1 followed by 19 zeroes 74 }