Skip to content

Commit f59aafd

Browse files
committed
- kotlin 1.1 beta
- fixed byte extensions
1 parent c094f27 commit f59aafd

File tree

5 files changed

+60
-31
lines changed

5 files changed

+60
-31
lines changed

build.gradle.kts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
val kotlinVersion = "1.1-M04"
2-
31
buildscript {
42

53
repositories {
64
gradleScriptKotlin()
75
}
86

97
dependencies {
10-
classpath(kotlinModule("gradle-plugin", "1.1-M04"))
8+
classpath(kotlinModule("gradle-plugin", "1.1.0-beta-17"))
119
}
1210
}
1311

@@ -21,11 +19,6 @@ repositories {
2119
}
2220

2321
dependencies {
24-
compile(kotlinModule("stdlib", "1.1-M04"))
22+
compile(kotlinModule("stdlib", "1.1.0-beta-17"))
2523
testCompile("io.kotlintest:kotlintest:1.3.5")
26-
}
27-
28-
29-
task("embeddedKotlinVersion") {
30-
println("$embeddedKotlinVersion")
3124
}

src/main/kotlin/Byte.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Created by elect on 19/01/2017.
3+
*/
4+
5+
infix fun Byte.udiv(b: Byte) = (toUInt() / b.toUInt()).toByte()
6+
7+
infix fun Byte.urem(b: Byte) = (toUInt() % b.toUInt()).toByte()
8+
infix fun Byte.ucmp(b: Byte) = toUInt().compareTo(b.toUInt())
9+
infix fun Byte.ushr(b: Byte) = (toUInt() ushr b.toUInt()).toByte()
10+
11+
infix fun Byte.udiv(b: Int) = (toUInt() / b).toByte()
12+
infix fun Byte.urem(b: Int) = (toUInt() % b).toByte()
13+
infix fun Byte.ucmp(b: Int) = toUInt().compareTo(b)
14+
infix fun Byte.ushr(b: Int) = (toUInt() ushr b).toByte()
15+
16+
fun Byte.toUbyte() = Ubyte(this)
17+
fun Byte.toUint() = Uint(toUInt())
18+
fun Byte.toUlong() = Ulong(toUInt())
19+
fun Byte.toUshort() = Ushort(toUInt())
20+
21+
val Byte.ub
22+
get() = toUbyte()
23+
val Byte.ui
24+
get() = toUint()
25+
val Byte.ul
26+
get() = toUlong()
27+
val Byte.us
28+
get() = toUshort()

src/main/kotlin/unsigned.kt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@ import java.math.BigInteger
44
* Created by GBarbieri on 06.10.2016.
55
*/
66

7-
infix fun Byte.udiv(b: Byte) = (toUInt() / b.toUInt()).toByte()
8-
infix fun Byte.urem(b: Byte) = (toUInt() % b.toUInt()).toByte()
9-
infix fun Byte.ucmp(b: Byte) = toUInt().compareTo(b.toUInt())
10-
infix fun Byte.ushr(b: Byte) = (toUInt() ushr b.toUInt()).toByte()
117

12-
infix fun Byte.udiv(b: Int) = (toUInt() / b).toByte()
13-
infix fun Byte.urem(b: Int) = (toUInt() % b).toByte()
14-
infix fun Byte.ucmp(b: Int) = toUInt().compareTo(b)
15-
infix fun Byte.ushr(b: Int) = (toUInt() ushr b).toByte()
168

179
infix fun Short.udiv(b: Short) = (toUInt() / b.toUInt()).toShort()
1810
infix fun Short.urem(b: Short) = (toUInt() % b.toUInt()).toShort()
@@ -44,7 +36,7 @@ infix fun Long.ucmp(b: Long) = java.lang.Long.compareUnsigned(this, b)
4436

4537
// TODO if == Ubyte?
4638
fun Number.toUbyte() = Ubyte(toByte())
47-
fun Number.toUint() = Uint(toInt())
39+
fun Number.toUint() = Uint(this)
4840
fun Number.toUlong() = Ulong(toLong())
4941
fun Number.toUshort() = Ushort(toShort())
5042

src/test/kotlin/test.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Created by elect on 19/01/2017.
3+
*/
4+
5+
val Number.ui
6+
get() = toUint()
7+
val Int.b
8+
get() = toByte()
9+
10+
fun main(args: Array<String>) {
11+
12+
val b = 255.b
13+
println(b.toUInt())
14+
println(b.toUint())
15+
println(b.ui)
16+
}

src/test/kotlin/unsigned.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import io.kotlintest.KTestJUnitRunner
2-
import io.kotlintest.matchers.Matchers
32
import io.kotlintest.matchers.be
43
import io.kotlintest.specs.StringSpec
54
import org.junit.runner.RunWith
@@ -12,18 +11,19 @@ import java.math.BigInteger
1211
@RunWith(KTestJUnitRunner::class)
1312
class unsigned : StringSpec() {
1413

15-
val Int.b: Byte
16-
get() = this.toByte()
17-
val Int.s: Short
18-
get() = this.toShort()
19-
val Long.b: Byte
20-
get() = this.toByte()
21-
val Long.s: Short
22-
get() = this.toShort()
23-
val Long.i: Int
24-
get() = this.toInt()
25-
val BigInteger.L: Long
26-
get() = this.toLong()
14+
val Int.b
15+
get() = toByte()
16+
val Int.s
17+
get() = toShort()
18+
val Long.b
19+
get() = toByte()
20+
val Long.s
21+
get() = toShort()
22+
val Long.i
23+
get() = toInt()
24+
val BigInteger.L
25+
get() = toLong()
26+
2727
/**
2828
* BUG, 0xffffffffffffffff is outside Long range
2929
* https://youtrack.jetbrains.com/issue/KT-4749

0 commit comments

Comments
 (0)