toStrictlyNegativeIntOrThrow

@ExperimentalSinceKotoolsTypes(version = "4.4")
fun Number.toStrictlyNegativeIntOrThrow(): StrictlyNegativeInt

Returns this number as a StrictlyNegativeInt, which may involve rounding or truncation, or throws an IllegalArgumentException if this number is positive.

Here's some usage examples:

val result: StrictlyNegativeInt = (-1).toStrictlyNegativeIntOrThrow()
println(result) // 1

0.toStrictlyNegativeIntOrThrow() // IllegalArgumentException
1.toStrictlyNegativeIntOrThrow() // IllegalArgumentException

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