Files
encoding.kt/src/commonMain/kotlin/com/infendro/encoding/util/Math.kt
Infendro 2e22903d18
Some checks failed
/ publish (push) Has been cancelled
initial commit
2025-07-12 18:13:30 +02:00

32 lines
421 B
Kotlin

package com.infendro.encoding.util
import kotlin.math.log2
internal fun log2(
value: Int,
): Double {
val x = value.toDouble()
return log2(x)
}
internal fun gcd(
a: Int,
b: Int,
): Int {
var x = a
var y = b
while (y != 0) {
val temp = y
y = x % y
x = temp
}
return x
}
internal fun lcm(
a: Int,
b: Int,
): Int {
return (a * b) / gcd(a, b)
}