Add operator 'rem' as extension to BigInteger
#KT-14650 Fixed Note that after this change behaviour of '%' on BigInteger is changed, now it works like a proper remainder
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// LANGUAGE_VERSION: 1.0
|
||||
// FULL_JDK
|
||||
|
||||
import java.math.BigInteger
|
||||
|
||||
fun box(): String {
|
||||
val m = BigInteger.valueOf(-2) % BigInteger.valueOf(3)
|
||||
return if (m != BigInteger.valueOf(1)) "Fail: BigInteger(-2) mod BigInteger(3) == $m" else "OK"
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
public final class PercentAsModOnBigIntegerWithoutRemKt {
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
}
|
||||
+6
@@ -10547,6 +10547,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("percentAsModOnBigIntegerWithoutRem.kt")
|
||||
public void testPercentAsModOnBigIntegerWithoutRem() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/percentAsModOnBigIntegerWithoutRem.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("remAssignmentOperation.kt")
|
||||
public void testRemAssignmentOperation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/remAssignmentOperation.kt");
|
||||
|
||||
@@ -10547,6 +10547,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("percentAsModOnBigIntegerWithoutRem.kt")
|
||||
public void testPercentAsModOnBigIntegerWithoutRem() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/percentAsModOnBigIntegerWithoutRem.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("remAssignmentOperation.kt")
|
||||
public void testRemAssignmentOperation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/remAssignmentOperation.kt");
|
||||
|
||||
@@ -10547,6 +10547,12 @@ public class LightAnalysisModeCodegenTestGenerated extends AbstractLightAnalysis
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("percentAsModOnBigIntegerWithoutRem.kt")
|
||||
public void testPercentAsModOnBigIntegerWithoutRem() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/percentAsModOnBigIntegerWithoutRem.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("remAssignmentOperation.kt")
|
||||
public void testRemAssignmentOperation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/remAssignmentOperation.kt");
|
||||
|
||||
@@ -31,6 +31,13 @@ public inline operator fun BigInteger.times(other: BigInteger) : BigInteger = th
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun BigInteger.div(other: BigInteger) : BigInteger = this.divide(other)
|
||||
|
||||
/**
|
||||
* Enables the use of the `%` operator for [BigInteger] instances.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun BigInteger.rem(other: BigInteger) : BigInteger = this.remainder(other)
|
||||
|
||||
/**
|
||||
* Enables the use of the unary `-` operator for [BigInteger] instances.
|
||||
*/
|
||||
|
||||
@@ -17,7 +17,8 @@ class MathTest {
|
||||
assertEquals(BigInteger("6"), a * b)
|
||||
assertEquals(BigInteger("0"), a / b)
|
||||
assertEquals(BigInteger("-2"), -a)
|
||||
assertEquals(BigInteger("1"), -a % b)
|
||||
assertEquals(BigInteger("-2"), -a % b)
|
||||
assertEquals(BigInteger("1"), (-a).mod(b))
|
||||
assertEquals(BigInteger("-2"), (-a).remainder(b))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user