https://kotlinlang.org logo
Title
l

Lukasz Kalnik

02/15/2022, 4:32 PM
Is there a ready function in std lib which maps a value from one range (say
0..1
) to another range (say
1_000..5_000
)? Basically the equivalent of this:
fun getRangeValueAtInterval(start: Int, end: Int, interval: Float): Int =
    start + (interval * (end - start)).roundToInt()
Also as you see here I map from a
Float
range to an
Int
range.
j

Joffrey

02/15/2022, 4:34 PM
I don't believe there is any such thing. IMO it is simple enough to be implemented in user code, and too niche to deserve to be in the stdlib, so I guess that's why there is probably nothing in the stdlib in this respect.
👍 2