From c15c00677ee02ebd9679874378f95faf981e852c Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Tue, 13 Dec 2016 21:33:44 +0300 Subject: [PATCH] Add operator 'rem' as extension to BigDecimal Deprecate 'mod' operator --- libraries/stdlib/src/kotlin/util/BigNumbers.kt | 7 +++++++ libraries/stdlib/test/numbers/MathJVMTest.kt | 2 ++ 2 files changed, 9 insertions(+) diff --git a/libraries/stdlib/src/kotlin/util/BigNumbers.kt b/libraries/stdlib/src/kotlin/util/BigNumbers.kt index cd3fe0a0840..5af467f7e2e 100644 --- a/libraries/stdlib/src/kotlin/util/BigNumbers.kt +++ b/libraries/stdlib/src/kotlin/util/BigNumbers.kt @@ -76,8 +76,15 @@ public inline operator fun BigDecimal.div(other: BigDecimal) : BigDecimal = this * Enables the use of the `%` operator for [BigDecimal] instances. */ @kotlin.internal.InlineOnly +@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.WARNING) public inline operator fun BigDecimal.mod(other: BigDecimal) : BigDecimal = this.remainder(other) +/** + * Enables the use of the `%` operator for [BigDecimal] instances. + */ +@kotlin.internal.InlineOnly +public inline operator fun BigDecimal.rem(other: BigDecimal) : BigDecimal = this.remainder(other) + /** * Enables the use of the unary `-` operator for [BigDecimal] instances. */ diff --git a/libraries/stdlib/test/numbers/MathJVMTest.kt b/libraries/stdlib/test/numbers/MathJVMTest.kt index a668ba1a3ff..16d54f8a408 100644 --- a/libraries/stdlib/test/numbers/MathJVMTest.kt +++ b/libraries/stdlib/test/numbers/MathJVMTest.kt @@ -32,6 +32,8 @@ class MathTest { assertEquals(BigDecimal("2"), BigDecimal("4") / a) assertEquals(BigDecimal("-2"), -a) assertEquals(BigDecimal("-2"), -a % b) + assertEquals(BigDecimal("-2"), (-a).mod(b)) + assertEquals(BigDecimal("-2"), (-a).rem(b)) } }