From 2d85c437cd68c5791522202acf9a246b5238f717 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Thu, 26 Nov 2015 15:55:12 +0300 Subject: [PATCH] Final moves: BigInteger and BigDecimal operations --- libraries/stdlib/src/kotlin/math/JMath.kt | 11 ++++ .../stdlib/src/kotlin/util/BigNumbers.kt | 63 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 libraries/stdlib/src/kotlin/util/BigNumbers.kt diff --git a/libraries/stdlib/src/kotlin/math/JMath.kt b/libraries/stdlib/src/kotlin/math/JMath.kt index 2991a67cafe..5a66e0f0da2 100644 --- a/libraries/stdlib/src/kotlin/math/JMath.kt +++ b/libraries/stdlib/src/kotlin/math/JMath.kt @@ -9,55 +9,66 @@ import java.math.BigInteger /** * Enables the use of the `+` operator for [BigInteger] instances. */ +@Deprecated("Provided for binary compatibility", ReplaceWith("this.plus(other)"), level = DeprecationLevel.HIDDEN) public operator fun BigInteger.plus(other: BigInteger) : BigInteger = this.add(other) /** * Enables the use of the `-` operator for [BigInteger] instances. */ +@Deprecated("Provided for binary compatibility", ReplaceWith("this.minus(other)"), level = DeprecationLevel.HIDDEN) public operator fun BigInteger.minus(other: BigInteger) : BigInteger = this.subtract(other) /** * Enables the use of the `*` operator for [BigInteger] instances. */ +@Deprecated("Provided for binary compatibility", ReplaceWith("this.times(other)"), level = DeprecationLevel.HIDDEN) public operator fun BigInteger.times(other: BigInteger) : BigInteger = this.multiply(other) /** * Enables the use of the `/` operator for [BigInteger] instances. */ +@Deprecated("Provided for binary compatibility", ReplaceWith("this.div(other)"), level = DeprecationLevel.HIDDEN) public operator fun BigInteger.div(other: BigInteger) : BigInteger = this.divide(other) /** * Enables the use of the unary `-` operator for [BigInteger] instances. */ +@Deprecated("Provided for binary compatibility", ReplaceWith("this.unaryMinus()"), level = DeprecationLevel.HIDDEN) public operator fun BigInteger.unaryMinus() : BigInteger = this.negate() /** * Enables the use of the `+` operator for [BigDecimal] instances. */ +@Deprecated("Provided for binary compatibility", ReplaceWith("this.plus(other)"), level = DeprecationLevel.HIDDEN) public operator fun BigDecimal.plus(other: BigDecimal) : BigDecimal = this.add(other) /** * Enables the use of the `-` operator for [BigDecimal] instances. */ +@Deprecated("Provided for binary compatibility", ReplaceWith("this.minus(other)"), level = DeprecationLevel.HIDDEN) public operator fun BigDecimal.minus(other: BigDecimal) : BigDecimal = this.subtract(other) /** * Enables the use of the `*` operator for [BigDecimal] instances. */ +@Deprecated("Provided for binary compatibility", ReplaceWith("this.times(other)"), level = DeprecationLevel.HIDDEN) public operator fun BigDecimal.times(other: BigDecimal) : BigDecimal = this.multiply(other) /** * Enables the use of the `/` operator for [BigDecimal] instances. */ +@Deprecated("Provided for binary compatibility", ReplaceWith("this.div(other)"), level = DeprecationLevel.HIDDEN) public operator fun BigDecimal.div(other: BigDecimal) : BigDecimal = this.divide(other) /** * Enables the use of the `%` operator for [BigDecimal] instances. */ +@Deprecated("Provided for binary compatibility", ReplaceWith("this.mod(other)"), level = DeprecationLevel.HIDDEN) public operator fun BigDecimal.mod(other: BigDecimal) : BigDecimal = this.remainder(other) /** * Enables the use of the unary `-` operator for [BigDecimal] instances. */ +@Deprecated("Provided for binary compatibility", ReplaceWith("this.unaryMinus(other)"), level = DeprecationLevel.HIDDEN) public operator fun BigDecimal.unaryMinus() : BigDecimal = this.negate() diff --git a/libraries/stdlib/src/kotlin/util/BigNumbers.kt b/libraries/stdlib/src/kotlin/util/BigNumbers.kt new file mode 100644 index 00000000000..45488068f77 --- /dev/null +++ b/libraries/stdlib/src/kotlin/util/BigNumbers.kt @@ -0,0 +1,63 @@ +@file:kotlin.jvm.JvmMultifileClass +@file:kotlin.jvm.JvmName("MathKt") +@file:kotlin.jvm.JvmVersion +package kotlin + +import java.math.BigDecimal +import java.math.BigInteger + +/** + * Enables the use of the `+` operator for [BigInteger] instances. + */ +public operator fun BigInteger.plus(other: BigInteger) : BigInteger = this.add(other) + +/** + * Enables the use of the `-` operator for [BigInteger] instances. + */ +public operator fun BigInteger.minus(other: BigInteger) : BigInteger = this.subtract(other) + +/** + * Enables the use of the `*` operator for [BigInteger] instances. + */ +public operator fun BigInteger.times(other: BigInteger) : BigInteger = this.multiply(other) + +/** + * Enables the use of the `/` operator for [BigInteger] instances. + */ +public operator fun BigInteger.div(other: BigInteger) : BigInteger = this.divide(other) + +/** + * Enables the use of the unary `-` operator for [BigInteger] instances. + */ +public operator fun BigInteger.unaryMinus() : BigInteger = this.negate() + + +/** + * Enables the use of the `+` operator for [BigDecimal] instances. + */ +public operator fun BigDecimal.plus(other: BigDecimal) : BigDecimal = this.add(other) + +/** + * Enables the use of the `-` operator for [BigDecimal] instances. + */ +public operator fun BigDecimal.minus(other: BigDecimal) : BigDecimal = this.subtract(other) + +/** + * Enables the use of the `*` operator for [BigDecimal] instances. + */ +public operator fun BigDecimal.times(other: BigDecimal) : BigDecimal = this.multiply(other) + +/** + * Enables the use of the `/` operator for [BigDecimal] instances. + */ +public operator fun BigDecimal.div(other: BigDecimal) : BigDecimal = this.divide(other) + +/** + * Enables the use of the `%` operator for [BigDecimal] instances. + */ +public operator fun BigDecimal.mod(other: BigDecimal) : BigDecimal = this.remainder(other) + +/** + * Enables the use of the unary `-` operator for [BigDecimal] instances. + */ +public operator fun BigDecimal.unaryMinus() : BigDecimal = this.negate()