Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
encrywm.backend.Arith.scala Maven / Gradle / Ivy
package encrywm.backend
import encrywm.backend.executor.error.UnsupportedOperationError
object Arith {
def checkType[T](v: Any): T = v match {
case t: T@unchecked => t
case _ => throw UnsupportedOperationError
}
def add[T](op1: Any, op2: Any): T = {
(op1, op2) match {
case (o1: Int, o2: Int) => checkType[T](o1 + o2)
case (o1: Int, o2: Float) => checkType[T](o1 + o2)
case (o1: Int, o2: Double) => checkType[T](o1 + o2)
case (o1: Int, o2: Long) => checkType[T](o1 + o2)
case (o1: Float, o2: Float) => checkType[T](o1 + o2)
case (o1: Float, o2: Int) => checkType[T](o1 + o2)
case (o1: Float, o2: Double) => checkType[T](o1 + o2)
case (o1: Float, o2: Long) => checkType[T](o1 + o2)
case (o1: Double, o2: Float) => checkType[T](o1 + o2)
case (o1: Double, o2: Int) => checkType[T](o1 + o2)
case (o1: Double, o2: Double) => checkType[T](o1 + o2)
case (o1: Double, o2: Long) => checkType[T](o1 + o2)
case (o1: Long, o2: Float) => checkType[T](o1 + o2)
case (o1: Long, o2: Int) => checkType[T](o1 + o2)
case (o1: Long, o2: Double) => checkType[T](o1 + o2)
case (o1: Long, o2: Long) => checkType[T](o1 + o2)
case _ => throw UnsupportedOperationError
}
}
def sub[T](op1: Any, op2: Any): T = {
(op1, op2) match {
case (o1: Int, o2: Int) => checkType[T](o1 - o2)
case (o1: Int, o2: Float) => checkType[T](o1 - o2)
case (o1: Int, o2: Double) => checkType[T](o1 - o2)
case (o1: Int, o2: Long) => checkType[T](o1 - o2)
case (o1: Float, o2: Float) => checkType[T](o1 - o2)
case (o1: Float, o2: Int) => checkType[T](o1 + o2)
case (o1: Float, o2: Double) => checkType[T](o1 - o2)
case (o1: Float, o2: Long) => checkType[T](o1 - o2)
case (o1: Double, o2: Float) => checkType[T](o1 - o2)
case (o1: Double, o2: Int) => checkType[T](o1 - o2)
case (o1: Double, o2: Double) => checkType[T](o1 - o2)
case (o1: Double, o2: Long) => checkType[T](o1 - o2)
case (o1: Long, o2: Float) => checkType[T](o1 - o2)
case (o1: Long, o2: Int) => checkType[T](o1 - o2)
case (o1: Long, o2: Double) => checkType[T](o1 - o2)
case (o1: Long, o2: Long) => checkType[T](o1 - o2)
case _ => throw UnsupportedOperationError
}
}
def mul[T](op1: Any, op2: Any): T = {
(op1, op2) match {
case (o1: Int, o2: Int) => checkType[T](o1 * o2)
case (o1: Int, o2: Float) => checkType[T](o1 * o2)
case (o1: Int, o2: Double) => checkType[T](o1 * o2)
case (o1: Int, o2: Long) => checkType[T](o1 * o2)
case (o1: Float, o2: Float) => checkType[T](o1 * o2)
case (o1: Float, o2: Int) => checkType[T](o1 * o2)
case (o1: Float, o2: Double) => checkType[T](o1 * o2)
case (o1: Float, o2: Long) => checkType[T](o1 * o2)
case (o1: Double, o2: Float) => checkType[T](o1 * o2)
case (o1: Double, o2: Int) => checkType[T](o1 * o2)
case (o1: Double, o2: Double) => checkType[T](o1 * o2)
case (o1: Double, o2: Long) => checkType[T](o1 * o2)
case (o1: Long, o2: Float) => checkType[T](o1 * o2)
case (o1: Long, o2: Int) => checkType[T](o1 * o2)
case (o1: Long, o2: Double) => checkType[T](o1 * o2)
case (o1: Long, o2: Long) => checkType[T](o1 * o2)
case _ => throw UnsupportedOperationError
}
}
def div[T](op1: Any, op2: Any): T = {
(op1, op2) match {
case (o1: Int, o2: Int) => checkType[T](o1 / o2)
case (o1: Int, o2: Float) => checkType[T](o1 / o2)
case (o1: Int, o2: Double) => checkType[T](o1 / o2)
case (o1: Int, o2: Long) => checkType[T](o1 / o2)
case (o1: Float, o2: Float) => checkType[T](o1 / o2)
case (o1: Float, o2: Int) => checkType[T](o1 / o2)
case (o1: Float, o2: Double) => checkType[T](o1 / o2)
case (o1: Float, o2: Long) => checkType[T](o1 / o2)
case (o1: Double, o2: Float) => checkType[T](o1 / o2)
case (o1: Double, o2: Int) => checkType[T](o1 / o2)
case (o1: Double, o2: Double) => checkType[T](o1 / o2)
case (o1: Double, o2: Long) => checkType[T](o1 / o2)
case (o1: Long, o2: Float) => checkType[T](o1 / o2)
case (o1: Long, o2: Int) => checkType[T](o1 / o2)
case (o1: Long, o2: Double) => checkType[T](o1 / o2)
case (o1: Long, o2: Long) => checkType[T](o1 / o2)
case _ => throw UnsupportedOperationError
}
}
}