Skip to content

Commit 5928b52

Browse files
committed
- restructuration in progress
- upgraded to 1.1-b38 - tests broken (kotlintest is 1.0-m04)
1 parent eb2fe20 commit 5928b52

File tree

8 files changed

+458
-147
lines changed

8 files changed

+458
-147
lines changed

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
}
66

77
dependencies {
8-
classpath(kotlinModule("gradle-plugin", "1.1.0-beta-17"))
8+
classpath(kotlinModule("gradle-plugin", "1.1.0-beta-38"))
99
}
1010
}
1111

@@ -19,6 +19,6 @@ repositories {
1919
}
2020

2121
dependencies {
22-
compile(kotlinModule("stdlib", "1.1.0-beta-17"))
22+
compile(kotlinModule("stdlib", "1.1.0-beta-38"))
2323
testCompile("io.kotlintest:kotlintest:1.3.5")
2424
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Created by GBarbieri on 03.02.2017.
3+
*/
4+
5+
package unsigned
6+
7+
import java.math.BigInteger
8+
9+
10+
infix fun BigInteger.ushr(bitCount: Int) = shiftRight(bitCount)

src/main/kotlin/unsigned/Byte.kt

Lines changed: 90 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
package unsigned
2-
3-
import unsigned.toUInt
4-
51
/**
62
* Created by elect on 19/01/2017.
73
*/
84

9-
infix fun Byte.udiv(b: Byte) = (toUInt() / b.toUInt()).toByte()
5+
package unsigned
106

11-
infix fun Byte.urem(b: Byte) = (toUInt() % b.toUInt()).toByte()
12-
infix fun Byte.ucmp(b: Byte) = toUInt().compareTo(b.toUInt())
13-
infix fun Byte.ushr(b: Byte) = (toUInt() ushr b.toUInt()).toByte()
7+
import toBigInt
8+
import java.math.BigInteger
9+
import kotlin.experimental.and
10+
import kotlin.experimental.or
11+
import kotlin.experimental.xor
1412

15-
infix fun Byte.udiv(b: Int) = (toUInt() / b).toByte()
16-
infix fun Byte.urem(b: Int) = (toUInt() % b).toByte()
17-
infix fun Byte.ucmp(b: Int) = toUInt().compareTo(b)
18-
infix fun Byte.ushr(b: Int) = (toUInt() ushr b).toByte()
13+
14+
fun Byte.toUShort() = toUInt().toShort()
15+
fun Byte.toUInt() = toInt() and 0xff
16+
fun Byte.toULong() = toUInt().toLong()
17+
fun Byte.toBigInt() = BigInteger.valueOf(toULong())
1918

2019
fun Byte.toUbyte() = Ubyte(this)
20+
fun Byte.toUshort() = Ushort(toUInt())
2121
fun Byte.toUint() = Uint(toUInt())
2222
fun Byte.toUlong() = Ulong(toUInt())
23-
fun Byte.toUshort() = Ushort(toUInt())
2423

2524
val Byte.ub
2625
get() = toUbyte()
@@ -29,4 +28,81 @@ val Byte.ui
2928
val Byte.ul
3029
get() = toUlong()
3130
val Byte.us
32-
get() = toUshort()
31+
get() = toUshort()
32+
33+
infix fun Byte.udiv(b: Byte) = (toUInt() / b.toUInt()).toByte()
34+
infix fun Byte.urem(b: Byte) = (toUInt() % b.toUInt()).toByte()
35+
infix fun Byte.ucmp(b: Byte) = toUInt().compareTo(b.toUInt())
36+
infix fun Byte.ushr(b: Byte) = (toUInt() ushr b.toUInt()).toByte()
37+
38+
infix fun Byte.udiv(b: Short) = (toUInt() / b.toUInt()).toByte()
39+
infix fun Byte.urem(b: Short) = (toUInt() % b.toUInt()).toByte()
40+
infix fun Byte.ucmp(b: Short) = toUInt().compareTo(b.toUInt())
41+
infix fun Byte.ushr(b: Short) = (toUInt() ushr b.toUInt()).toByte()
42+
43+
infix fun Byte.udiv(b: Int) = (toULong() / b.toULong()).toByte()
44+
infix fun Byte.urem(b: Int) = (toULong() % b.toULong()).toByte()
45+
infix fun Byte.ucmp(b: Int) = toULong().compareTo(b.toULong())
46+
infix fun Byte.ushr(b: Int) = (toUInt() ushr b).toByte()
47+
48+
infix fun Byte.udiv(b: Long) = (toBigInt() / b.toBigInt()).toByte()
49+
infix fun Byte.urem(b: Long) = (toBigInt() % b.toBigInt()).toByte()
50+
infix fun Byte.ucmp(b: Long) = toBigInt().compareTo(b.toBigInt())
51+
// no Byte ushr Long
52+
53+
54+
operator fun Byte.plus(b: Ubyte) = (this + b.v).toByte()
55+
operator fun Byte.minus(b: Ubyte) = (this - b.v).toByte()
56+
operator fun Byte.times(b: Ubyte) = (this * b.v).toByte()
57+
infix fun Byte.and(b: Ubyte) = this and b.v
58+
infix fun Byte.or(b: Ubyte) = this or b.v
59+
infix fun Byte.xor(b: Ubyte) = this xor b.v
60+
infix fun Byte.shl(b: Ubyte) = (toInt() shl b.toInt()).toByte()
61+
62+
infix fun Byte.udiv(b: Ubyte) = (toUInt() / b.toInt()).toByte()
63+
infix fun Byte.urem(b: Ubyte) = (toUInt() % b.toInt()).toByte()
64+
infix fun Byte.ucmp(b: Ubyte) = toUInt().compareTo(b.toInt())
65+
infix fun Byte.ushr(b: Ubyte) = (toUInt() ushr b.toInt()).toByte()
66+
67+
68+
operator fun Byte.plus(b: Ushort) = (this + b.v).toByte()
69+
operator fun Byte.minus(b: Ushort) = (this - b.v).toByte()
70+
operator fun Byte.times(b: Ushort) = (this * b.v).toByte()
71+
infix fun Byte.and(b: Ushort) = this and b.toByte()
72+
infix fun Byte.or(b: Ushort) = this or b.toByte()
73+
infix fun Byte.xor(b: Ushort) = this xor b.toByte()
74+
infix fun Byte.shl(b: Ushort) = (toInt() shl b.toInt()).toByte()
75+
76+
infix fun Byte.udiv(b: Ushort) = (toUInt() / b.toInt()).toByte()
77+
infix fun Byte.urem(b: Ushort) = (toUInt() % b.toInt()).toByte()
78+
infix fun Byte.ucmp(b: Ushort) = toUInt().compareTo(b.toInt())
79+
infix fun Byte.ushr(b: Ushort) = (toUInt() ushr b.toInt()).toByte()
80+
81+
82+
operator fun Byte.plus(b: Uint) = (this + b.v).toByte()
83+
operator fun Byte.minus(b: Uint) = (this - b.v).toByte()
84+
operator fun Byte.times(b: Uint) = (this * b.v).toByte()
85+
infix fun Byte.and(b: Uint) = this and b.toByte()
86+
infix fun Byte.or(b: Uint) = this or b.toByte()
87+
infix fun Byte.xor(b: Uint) = this xor b.toByte()
88+
infix fun Byte.shl(b: Uint) = (toInt() shl b.v).toByte()
89+
90+
infix fun Byte.udiv(b: Uint) = (toULong() / b.toLong()).toByte()
91+
infix fun Byte.urem(b: Uint) = (toULong() % b.toLong()).toByte()
92+
infix fun Byte.ucmp(b: Uint) = toULong().compareTo(b.toLong())
93+
infix fun Byte.ushr(b: Uint) = (toUInt() ushr b.toInt()).toByte()
94+
95+
96+
operator fun Byte.plus(b: Ulong) = (this + b.v).toByte()
97+
operator fun Byte.minus(b: Ulong) = (this - b.v).toByte()
98+
operator fun Byte.times(b: Ulong) = (this * b.v).toByte()
99+
infix fun Byte.and(b: Ulong) = this and b.toByte()
100+
infix fun Byte.or(b: Ulong) = this or b.toByte()
101+
infix fun Byte.xor(b: Ulong) = this xor b.toByte()
102+
infix fun Byte.shl(b: Ulong) = (toInt() shl b.toInt()).toByte()
103+
104+
infix fun Byte.udiv(b: Ulong) = (toULong() / b.toLong()).toByte()
105+
infix fun Byte.urem(b: Ulong) = (toULong() % b.toLong()).toByte()
106+
infix fun Byte.ucmp(b: Ulong) = toULong().compareTo(b.toLong())
107+
// no Byte ushr Ulong
108+

src/main/kotlin/unsigned/Int.kt

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/**
2+
* Created by GBarbieri on 30.01.2017.
3+
*/
4+
5+
package unsigned
6+
7+
import toBigInt
8+
import java.math.BigInteger
9+
10+
11+
fun Int.toUByte() = toByte()
12+
fun Int.toUShort() = toShort()
13+
fun Int.toULong() = toLong() and 0xffffffffL
14+
fun Int.toBigInt() = BigInteger.valueOf(toULong())
15+
16+
fun Int.toUbyte() = Ubyte(this)
17+
fun Int.toUshort() = Ushort(this)
18+
fun Int.toUint() = Uint(this)
19+
fun Int.toUlong() = Ulong(toULong())
20+
21+
val Int.ub
22+
get() = toUbyte()
23+
val Int.ui
24+
get() = toUint()
25+
val Int.ul
26+
get() = toUlong()
27+
val Int.us
28+
get() = toUshort()
29+
30+
infix fun Int.udiv(b: Byte) = (toULong() / b.toUInt()).toInt()
31+
infix fun Int.urem(b: Byte) = (toULong() % b.toUInt()).toInt()
32+
infix fun Int.ucmp(b: Byte) = toULong().compareTo(b.toUInt())
33+
infix fun Int.ushr(b: Byte) = (toULong() ushr b.toUInt()).toInt()
34+
35+
infix fun Int.udiv(b: Short) = (toULong() / b.toUInt()).toInt()
36+
infix fun Int.urem(b: Short) = (toULong() % b.toUInt()).toInt()
37+
infix fun Int.ucmp(b: Short) = toULong().compareTo(b.toUInt())
38+
infix fun Int.ushr(b: Short) = (toULong() ushr b.toUInt()).toInt()
39+
40+
infix fun Int.udiv(b: Int) = (toULong() / b.toULong()).toInt()
41+
infix fun Int.urem(b: Int) = (toULong() % b.toULong()).toInt()
42+
infix fun Int.ucmp(b: Int) = toULong().compareTo(b.toULong())
43+
infix fun Int.ushr(b: Int) = (toULong() ushr b).toInt()
44+
45+
infix fun Int.udiv(b: Long) = (toBigInt() / b.toBigInt()).toInt()
46+
infix fun Int.urem(b: Long) = (toBigInt() % b.toBigInt()).toInt()
47+
infix fun Int.ucmp(b: Long) = toBigInt().compareTo(b.toBigInt())
48+
// no Int ushr Long
49+
50+
51+
operator fun Int.plus(b: Ubyte) = this + b.v
52+
operator fun Int.minus(b: Ubyte) = this - b.v
53+
operator fun Int.times(b: Ubyte) = this * b.v
54+
infix fun Int.and(b: Ubyte) = this and b.toInt()
55+
infix fun Int.or(b: Ubyte) = this or b.toInt()
56+
infix fun Int.xor(b: Ubyte) = this xor b.toInt()
57+
infix fun Int.shl(b: Ubyte) = this shl b.toInt()
58+
59+
infix fun Int.udiv(b: Ubyte) = (toULong() / b.toLong()).toInt()
60+
infix fun Int.urem(b: Ubyte) = (toULong() % b.toLong()).toInt()
61+
infix fun Int.ucmp(b: Ubyte) = toULong().compareTo(b.toLong())
62+
infix fun Int.ushr(b: Ubyte) = this ushr b.toInt()
63+
64+
65+
operator fun Int.plus(b: Ushort) = this + b.v
66+
operator fun Int.minus(b: Ushort) = this - b.v
67+
operator fun Int.times(b: Ushort) = this * b.v
68+
infix fun Int.and(b: Ushort) = this and b.toInt()
69+
infix fun Int.or(b: Ushort) = this or b.toInt()
70+
infix fun Int.xor(b: Ushort) = this xor b.toInt()
71+
infix fun Int.shl(b: Ushort) = this shl b.toInt()
72+
73+
infix fun Int.udiv(b: Ushort) = (toULong() / b.toLong()).toInt()
74+
infix fun Int.urem(b: Ushort) = (toULong() % b.toLong()).toInt()
75+
infix fun Int.ucmp(b: Ushort) = toULong().compareTo(b.toLong())
76+
infix fun Int.ushr(b: Ushort) = (toULong() ushr b.toInt()).toInt()
77+
78+
79+
operator fun Int.plus(b: Uint) = this + b.v
80+
operator fun Int.minus(b: Uint) = this - b.v
81+
operator fun Int.times(b: Uint) = this * b.v
82+
infix fun Int.and(b: Uint) = this and b.toInt()
83+
infix fun Int.or(b: Uint) = this or b.toInt()
84+
infix fun Int.xor(b: Uint) = this xor b.toInt()
85+
infix fun Int.shl(b: Uint) = this shl b.v
86+
87+
infix fun Int.udiv(b: Uint) = (toULong() / b.toLong()).toInt()
88+
infix fun Int.urem(b: Uint) = (toULong() % b.toLong()).toInt()
89+
infix fun Int.ucmp(b: Uint) = toULong().compareTo(b.toLong())
90+
infix fun Int.ushr(b: Uint) = (toULong() ushr b.toInt()).toInt()
91+
92+
93+
operator fun Int.plus(b: Ulong) = (this + b.v).toInt()
94+
operator fun Int.minus(b: Ulong) = (this - b.v).toInt()
95+
operator fun Int.times(b: Ulong) = (this * b.v).toInt()
96+
infix fun Int.and(b: Ulong) = this and b.toInt()
97+
infix fun Int.or(b: Ulong) = this or b.toInt()
98+
infix fun Int.xor(b: Ulong) = this xor b.toInt()
99+
infix fun Int.shl(b: Ulong) = this shl b.toInt()
100+
101+
infix fun Int.udiv(b: Ulong) = (toULong() / b.toLong()).toInt()
102+
infix fun Int.urem(b: Ulong) = (toULong() % b.toLong()).toInt()
103+
infix fun Int.ucmp(b: Ulong) = toULong().compareTo(b.toLong())
104+
// no Int ushr Ulong

src/main/kotlin/unsigned/Long.kt

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import unsigned.*
2+
import java.math.BigInteger
3+
4+
/**
5+
* Created by GBarbieri on 31.01.2017.
6+
*/
7+
8+
fun Long.toUByte() = toByte()
9+
fun Long.toUShort() = toShort()
10+
fun Long.toUInt() = toInt()
11+
fun Long.toBigInt() = BigInteger(java.lang.Long.toUnsignedString(this))
12+
13+
fun Long.toUbyte() = Ubyte(this)
14+
fun Long.toUshort() = Ushort(this)
15+
fun Long.toUint() = Uint(this)
16+
fun Long.toUlong() = Ulong(this)
17+
18+
val Long.ub
19+
get() = toUbyte()
20+
val Long.ui
21+
get() = toUint()
22+
val Long.ul
23+
get() = toUlong()
24+
val Long.us
25+
get() = toUshort()
26+
27+
infix fun Long.udiv(b: Byte) = (toBigInt() / b.toBigInt()).toLong()
28+
infix fun Long.urem(b: Byte) = (toBigInt() % b.toBigInt()).toLong()
29+
infix fun Long.ucmp(b: Byte) = toBigInt().compareTo(b.toBigInt())
30+
infix fun Long.ushr(b: Byte) = (toBigInt() ushr b.toUInt()).toLong()
31+
32+
infix fun Long.udiv(b: Short) = (toBigInt() / b.toBigInt()).toLong()
33+
infix fun Long.urem(b: Short) = (toBigInt() % b.toBigInt()).toLong()
34+
infix fun Long.ucmp(b: Short) = toBigInt().compareTo(b.toBigInt())
35+
infix fun Long.ushr(b: Short) = (toBigInt() ushr b.toUInt()).toLong()
36+
37+
infix fun Long.udiv(b: Int) = (toBigInt() / b.toBigInt()).toLong()
38+
infix fun Long.urem(b: Int) = (toBigInt() % b.toBigInt()).toLong()
39+
infix fun Long.ucmp(b: Int) = toBigInt().compareTo(b.toBigInt())
40+
infix fun Long.ushr(b: Int) = (toBigInt() ushr b).toLong()
41+
42+
infix fun Long.udiv(b: Long) = (toBigInt() / b.toBigInt()).toLong()
43+
infix fun Long.urem(b: Long) = (toBigInt() % b.toBigInt()).toLong()
44+
infix fun Long.ucmp(b: Long) = toBigInt().compareTo(b.toBigInt())
45+
// no Long ushr Long
46+
47+
48+
operator fun Long.plus(b: Ubyte) = this + b.v
49+
operator fun Long.minus(b: Ubyte) = this - b.v
50+
operator fun Long.times(b: Ubyte) = this * b.v
51+
infix fun Long.and(b: Ubyte) = this and b.toLong()
52+
infix fun Long.or(b: Ubyte) = this or b.toLong()
53+
infix fun Long.xor(b: Ubyte) = this xor b.toLong()
54+
infix fun Long.shl(b: Ubyte) = this shl b.toInt()
55+
56+
infix fun Long.udiv(b: Ubyte) = (toBigInt() / b.toBigInt()).toLong()
57+
infix fun Long.urem(b: Ubyte) = (toBigInt() % b.toBigInt()).toLong()
58+
infix fun Long.ucmp(b: Ubyte) = toBigInt().compareTo(b.toBigInt())
59+
infix fun Long.ushr(b: Ubyte) = this ushr b.toInt()
60+
61+
62+
operator fun Long.plus(b: Ushort) = this + b.v
63+
operator fun Long.minus(b: Ushort) = this - b.v
64+
operator fun Long.times(b: Ushort) = this * b.v
65+
infix fun Long.and(b: Ushort) = this and b.toLong()
66+
infix fun Long.or(b: Ushort) = this or b.toLong()
67+
infix fun Long.xor(b: Ushort) = this xor b.toLong()
68+
infix fun Long.shl(b: Ushort) = this shl b.toInt()
69+
70+
infix fun Long.udiv(b: Ushort) = (toBigInt() / b.toBigInt()).toLong()
71+
infix fun Long.urem(b: Ushort) = (toBigInt() % b.toBigInt()).toLong()
72+
infix fun Long.ucmp(b: Ushort) = toBigInt().compareTo(b.toBigInt())
73+
infix fun Long.ushr(b: Ushort) = (toBigInt() ushr b.toInt()).toLong()
74+
75+
76+
operator fun Long.plus(b: Uint) = this + b.v
77+
operator fun Long.minus(b: Uint) = this - b.v
78+
operator fun Long.times(b: Uint) = this * b.v
79+
infix fun Long.and(b: Uint) = this and b.toLong()
80+
infix fun Long.or(b: Uint) = this or b.toLong()
81+
infix fun Long.xor(b: Uint) = this xor b.toLong()
82+
infix fun Long.shl(b: Uint) = this shl b.v
83+
84+
infix fun Long.udiv(b: Uint) = (toBigInt() / b.toBigInt()).toLong()
85+
infix fun Long.urem(b: Uint) = (toBigInt() % b.toBigInt()).toLong()
86+
infix fun Long.ucmp(b: Uint) = toBigInt().compareTo(b.toBigInt())
87+
infix fun Long.ushr(b: Uint) = (toBigInt() ushr b.toInt()).toLong()
88+
89+
90+
operator fun Long.plus(b: Ulong) = this + b.v
91+
operator fun Long.minus(b: Ulong) = this - b.v
92+
operator fun Long.times(b: Ulong) = this * b.v
93+
infix fun Long.and(b: Ulong) = this and b.toLong()
94+
infix fun Long.or(b: Ulong) = this or b.toLong()
95+
infix fun Long.xor(b: Ulong) = this xor b.toLong()
96+
infix fun Long.shl(b: Ulong) = this shl b.toInt()
97+
98+
infix fun Long.udiv(b: Ulong) = (toBigInt() / b.toBigInt()).toLong()
99+
infix fun Long.urem(b: Ulong) = (toBigInt() % b.toBigInt()).toLong()
100+
infix fun Long.ucmp(b: Ulong) = toBigInt().compareTo(b.toBigInt())
101+
// no Int ushr Ulong

0 commit comments

Comments
 (0)