Skip to content

Commit b1cce26

Browse files
committed
mod -> rem
1 parent 4b2a65f commit b1cce26

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/kotlin/unsigned.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,40 @@ import java.math.BigInteger
55
*/
66

77
infix fun Byte.udiv(b: Byte) = (toUInt() / b.toUInt()).toByte()
8-
infix fun Byte.umod(b: Byte) = (toUInt() % b.toUInt()).toByte()
8+
infix fun Byte.urem(b: Byte) = (toUInt() % b.toUInt()).toByte()
99
infix fun Byte.ucmp(b: Byte) = toUInt().compareTo(b.toUInt())
1010
infix fun Byte.ushr(b: Byte) = (toUInt() ushr b.toUInt()).toByte()
1111

1212
infix fun Byte.udiv(b: Int) = (toUInt() / b).toByte()
13-
infix fun Byte.umod(b: Int) = (toUInt() % b).toByte()
13+
infix fun Byte.urem(b: Int) = (toUInt() % b).toByte()
1414
infix fun Byte.ucmp(b: Int) = toUInt().compareTo(b)
1515
infix fun Byte.ushr(b: Int) = (toUInt() ushr b).toByte()
1616

1717
infix fun Short.udiv(b: Short) = (toUInt() / b.toUInt()).toShort()
18-
infix fun Short.umod(b: Short) = (toUInt() % b.toUInt()).toShort()
18+
infix fun Short.urem(b: Short) = (toUInt() % b.toUInt()).toShort()
1919
infix fun Short.ucmp(b: Short) = toUInt().compareTo(b.toUInt())
2020
infix fun Short.ushr(b: Short) = (toUInt() ushr b.toUInt()).toShort()
2121

2222
infix fun Short.udiv(b: Int) = (toUInt() / b).toShort()
23-
infix fun Short.umod(b: Int) = (toUInt() % b).toShort()
23+
infix fun Short.urem(b: Int) = (toUInt() % b).toShort()
2424
infix fun Short.ucmp(b: Int) = toUInt().compareTo(b)
2525
infix fun Short.ushr(b: Int) = (toUInt() ushr b).toShort()
2626

2727
infix fun Int.udiv(b: Byte) = Integer.divideUnsigned(this, b.toUInt())
28-
infix fun Int.umod(b: Byte) = Integer.remainderUnsigned(this, b.toUInt())
28+
infix fun Int.urem(b: Byte) = Integer.remainderUnsigned(this, b.toUInt())
2929
infix fun Int.ucmp(b: Byte) = Integer.compareUnsigned(this, b.toUInt())
3030
// Int.ushl(b: Int) is already provided by Kotlin lib
3131
infix fun Int.udiv(b: Short) = Integer.divideUnsigned(this, b.toUInt())
32-
infix fun Int.umod(b: Short) = Integer.remainderUnsigned(this, b.toUInt())
32+
infix fun Int.urem(b: Short) = Integer.remainderUnsigned(this, b.toUInt())
3333
infix fun Int.ucmp(b: Short) = Integer.compareUnsigned(this, b.toUInt())
3434
// Int.ushl(b: Int) is already provided by Kotlin lib
3535
infix fun Int.udiv(b: Int) = Integer.divideUnsigned(this, b)
36-
infix fun Int.umod(b: Int) = Integer.remainderUnsigned(this, b)
36+
infix fun Int.urem(b: Int) = Integer.remainderUnsigned(this, b)
3737
infix fun Int.ucmp(b: Int) = Integer.compareUnsigned(this, b)
3838
// Int.ushl(b: Int) is already provided by Kotlin lib
3939

4040
infix fun Long.udiv(b: Long) = java.lang.Long.divideUnsigned(this, b)
41-
infix fun Long.umod(b: Long) = java.lang.Long.remainderUnsigned(this, b)
41+
infix fun Long.urem(b: Long) = java.lang.Long.remainderUnsigned(this, b)
4242
infix fun Long.ucmp(b: Long) = java.lang.Long.compareUnsigned(this, b)
4343
// Long.ushl(b: Long) is already provided by Kotlin lib
4444

src/test/kotlin/unsigned.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,24 @@ class unsigned : StringSpec() {
4242
"primitive" {
4343

4444
250.b udiv 50.b shouldBe 5.b
45-
250.b umod 200.b shouldBe 50.b
45+
250.b urem 200.b shouldBe 50.b
4646
250.b ucmp 251.b should be lt 1
4747
(250.b ucmp 250.b) shouldBe 0
4848
0b1010_1010.b ushr 4 shouldBe 0b1010.b
4949

5050
65500.s udiv 500.s shouldBe 131.s
51-
65500.s umod 65000.s shouldBe 500.s
51+
65500.s urem 65000.s shouldBe 500.s
5252
65500.s ucmp 65501.s should be lt 1
5353
65500.s ucmp 65500.s shouldBe 0
5454
0b0100_1100_0011_1101.s ushr 8 shouldBe 0b100_1100.s
5555

5656
4_000_000_000.i udiv 2 shouldBe 2_000_000_000
57-
2_750_000_000.i umod 2_000_000_000 shouldBe 750_000_000
57+
2_750_000_000.i urem 2_000_000_000 shouldBe 750_000_000
5858
4_000_000_000.i ucmp 4_000_000_001.i should be lt 1
5959
4_000_000_000.i ucmp 4_000_000_000.i shouldBe 0
6060

6161
"18_000_000_000_000_000_000".L udiv 2L shouldBe "9'000'000'000'000'000'000".L
62-
"17'000'000'000'000'000'000".L umod "9'000'000'000'000'000'000".L shouldBe "8'000'000'000'000'000'000".L
62+
"17'000'000'000'000'000'000".L urem "9'000'000'000'000'000'000".L shouldBe "8'000'000'000'000'000'000".L
6363
"18'000'000'000'000'000'000".L ucmp "18'000'000'000'000'000'001".L should be lt 1
6464
"18'000'000'000'000'000'001".L ucmp "18'000'000'000'000'000'001".L shouldBe 0
6565
}

0 commit comments

Comments
 (0)