From d269de2bc6c1900a31cd6304ce2d2deb6e4bfa3c Mon Sep 17 00:00:00 2001 From: Iaroslav Postovalov Date: Mon, 20 Jul 2020 11:10:55 +0700 Subject: [PATCH] Implement dynamic operations routing for RemainderDivision --- .../scientifik/kmath/operations/OptionalOperations.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/OptionalOperations.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/OptionalOperations.kt index da7c2c73f..21a263ebd 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/OptionalOperations.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/OptionalOperations.kt @@ -93,6 +93,17 @@ interface RemainderDivisionOperations : RingOperations { * 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.rem(arg: T): T = arg.context { this@rem rem arg }