Implement dynamic operations routing for RemainderDivision

This commit is contained in:
Iaroslav Postovalov 2020-07-20 11:10:55 +07:00
parent 4d18a5f582
commit d269de2bc6
No known key found for this signature in database
GPG Key ID: 70D5F4DCB0972F1B

View File

@ -93,6 +93,17 @@ interface RemainderDivisionOperations<T> : RingOperations<T> {
* Performs the floored division of this value by [arg].
*/
infix fun T.div(arg: T): T
override fun binaryOperation(operation: String, left: T, right: T): T = when (operation) {
REM_OPERATION -> left rem right
DIV_OPERATION -> left div right
else -> super.binaryOperation(operation, left, right)
}
companion object {
const val REM_OPERATION = "rem"
const val DIV_OPERATION = "div"
}
}
infix fun <T : MathElement<out RemainderDivisionOperations<T>>> T.rem(arg: T): T = arg.context { this@rem rem arg }