Is there a cleaner way of writing this method? Preferably, I wouldn't need to match against all valid Types and instead permit every Type that has the * method. Also, is there a way to not require asInstanceOf[T] at the end?
def expr_neg[T <: AnyVal](value: T): T = value match { case int: Int => (int * -1).asInstanceOf[T] case long: Long => (long * -1).asInstanceOf[T] case float: Float => (float * -1).asInstanceOf[T] case double: Double => (double * -1).asInstanceOf[T] }