toStrictlyPositiveDoubleOrThrow

@ExperimentalSinceKotoolsTypes(version = "4.3.1")
fun Number.toStrictlyPositiveDoubleOrThrow(): StrictlyPositiveDouble

Returns this number as a StrictlyPositiveDouble, which may involve rounding or truncation, or throws IllegalArgumentException if this number is negative.

val result: StrictlyPositiveDouble = 1.toStrictlyPositiveDoubleOrThrow()
println(result) // 1.0

0.toStrictlyPositiveDoubleOrThrow() // IllegalArgumentException
(-1).toStrictlyPositiveDoubleOrThrow() // IllegalArgumentException

You can use the toStrictlyPositiveDoubleOrNull function for returning null instead of throwing an IllegalArgumentException when this number is negative.