I have the following
abstract interface Vec2t {
var x: T
var y: T
}
data class Vec2(override var x: Fl
Unfortunately there's no clean way to have generic abs function. You can work it around with the following abs
definition:
object glm {
fun <T : Number> abs(x: T): T {
val absoluteValue: Number = when (x) {
is Double -> Math.abs(x)
is Int -> Math.abs(x)
is Float -> Math.abs(x)
is BigDecimal -> x.abs()
is BigInteger -> x.abs()
else -> throw IllegalArgumentException("unsupported type ${x.javaClass}")
}
@Suppress("UNCHECKED_CAST")
return absoluteValue as T
}
}
Which would make it possible to use in your context:
fun abs(res: Vec2, a: Vec2): Vec2 {
res.x = glm.abs(a.x)
...
}