Since you're only really worried about the tens position, I'd just shift it once and check for 0..10:
fun Double.isSpecial() = (this * 10.0) in (0..10).map(Int::toDouble)
Testing with play.kotlinlang.org:
fun main() {
listOf(0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0).forEach(::checkSpecial)
listOf(0.01, 0.11, 0.22, 1.01).forEach(::checkSpecial)
}
fun checkSpecial(value: Double) {
println("$value isSpecial = ${value.isSpecial()}")
}
Outputs:
0.0 isSpecial = true
0.1 isSpecial = true
0.2 isSpecial = true
0.3 isSpecial = true
0.4 isSpecial = true
0.5 isSpecial = true
0.6 isSpecial = true
0.7 isSpecial = true
0.8 isSpecial = true
0.9 isSpecial = true
1.0 isSpecial = true
0.01 isSpecial = false
0.11 isSpecial = false
0.22 isSpecial = false
1.01 isSpecial = false
If you're less worried about elegance and more about performance, you could just do:
fun Double.isSpecial() = when (this) {
0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 -> true
else -> false
}
Which avoids allocating any sets or ranges entirely. If the range isn't dynamic, I'd just go with this, personally.