Usage: Round messages to 1K, files to 100MB (#20603)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
662248291e
Коммит
f639122376
@@ -229,3 +229,35 @@ func RoundOffToZeroes(n float64) int64 {
|
||||
firstDigit := int64(n) / tens
|
||||
return firstDigit * tens
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
func max(a, b int) int {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// RoundOffToZeroesResolution truncates off at most minResolution zero places.
|
||||
// It implicitly sets the lowest minResolution to 0.
|
||||
// e.g. 0 reports 1s, 1 reports 10s, 2 reports 100s, 3 reports 1000s
|
||||
func RoundOffToZeroesResolution(n float64, minResolution int) int64 {
|
||||
resolution := max(0, minResolution)
|
||||
if n >= -9 && n <= 9 {
|
||||
if resolution == 0 {
|
||||
return int64(n)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
zeroes := int(math.Log10(math.Abs(n)))
|
||||
resolution = min(zeroes, resolution)
|
||||
tens := int64(math.Pow10(resolution))
|
||||
significantDigits := int64(n) / tens
|
||||
return significantDigits * tens
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user