I tried:
import kotlin.Double.Companion.POSITIVE_INFINITY
import kotlin.Double.Companion.NaN
const val inf = POSITIVE_INFINITY
const val nan = NaN
But I get:
Const 'val' initializer should be a constant value
The reason I need to do this is because of Junit5's parametrized tests:
@ParameterizedTest
@ValueSource(doubles = doubleArrayOf(nan, inf, -2* epsilon, 1.5, -0.5, 1.0 + 2* epsilon))
fun ensureNotAProbability(number: Double)
{
...
}
Due to some limitations of Java annotations (described in this SO answer) the things 'passed to an annotation' can only be compile-time constants. Therefore I would need a compile time NaN, positive, and negative infinities.