Fix incorrect conversion of Long to String in base 36 in JS KT-48924

This commit is contained in:
Ilya Gorbunov
2022-03-25 21:04:30 +03:00
committed by teamcity
parent 03bb482322
commit 000165b12b
3 changed files with 57 additions and 7 deletions
+10 -3
View File
@@ -46,9 +46,16 @@ internal fun Long.toStringImpl(radix: Int): String {
}
}
// Do several (6) digits each time through the loop, so as to
// Do several digits each time through the loop, so as to
// minimize the calls to the very expensive emulated div.
val radixToPower = fromNumber(JsMath.pow(radix.toDouble(), 6.0))
val digitsPerTime = when {
radix == 2 -> 31
radix <= 10 -> 9
radix <= 21 -> 7
radix <= 35 -> 6
else -> 5
}
val radixToPower = fromNumber(JsMath.pow(radix.toDouble(), digitsPerTime.toDouble()))
var rem = this
var result = ""
@@ -61,7 +68,7 @@ internal fun Long.toStringImpl(radix: Int): String {
if (rem.isZero()) {
return digits + result
} else {
while (digits.length < 6) {
while (digits.length < digitsPerTime) {
digits = "0" + digits
}
result = digits + result