11package unsigned
22
3+ import unsigned.java_1_7.compareUnsigned
4+ import unsigned.java_1_7.divideUnsigned
5+ import unsigned.java_1_7.remainderUnsigned
36import java.math.BigInteger
47import kotlin.experimental.and
58import kotlin.experimental.inv
@@ -21,7 +24,7 @@ data class Ubyte(var v: Byte = 0) : Number() {
2124 }
2225
2326 constructor (number: Number ) : this (number.toByte())
24- @JvmOverloads constructor (string: String , base: Int = 10 ) : this (Integer .parseUnsignedInt(string.filter { it != ' _' && it != ' \' ' }, base).toShort ())
27+ @JvmOverloads constructor (string: String , base: Int = 10 ) : this (Integer .parseUnsignedInt(string.filter { it != ' _' && it != ' \' ' }, base).toByte ())
2528
2629 override fun toByte () = v
2730 override fun toShort () = v.toUInt().toShort()
@@ -57,11 +60,11 @@ data class Ubyte(var v: Byte = 0) : Number() {
5760
5861 infix operator fun div (b : Ubyte ) = Ubyte (toInt() / b.toInt())
5962 infix operator fun div (b : Byte ) = Ubyte (toInt() / b.toUInt())
60- infix operator fun div (b : Int ) = Ubyte (Integer .divideUnsigned( toInt(), b))
63+ infix operator fun div (b : Int ) = Ubyte (toInt().divideUnsigned( b))
6164
6265 infix operator fun rem (b : Ubyte ) = Ubyte (toInt() % b.toInt())
6366 infix operator fun rem (b : Byte ) = Ubyte (toInt() % b.toUInt())
64- infix operator fun rem (b : Int ) = Ubyte (Integer .remainderUnsigned( toInt(), b))
67+ infix operator fun rem (b : Int ) = Ubyte (toInt().remainderUnsigned( b))
6568
6669 // TODO add counterparts with res
6770
@@ -87,7 +90,7 @@ data class Ubyte(var v: Byte = 0) : Number() {
8790
8891 fun inv () = Ubyte (v.inv ())
8992
90- operator fun compareTo (b : Ubyte ) = Integer .compareUnsigned( toInt(), b.toInt())
91- operator fun compareTo (b : Byte ) = Integer .compareUnsigned( toInt(), b.toUInt())
92- operator fun compareTo (b : Int ) = Integer .compareUnsigned( toInt(), b)
93+ operator fun compareTo (b : Ubyte ) = toInt().compareUnsigned( b.toInt())
94+ operator fun compareTo (b : Byte ) = toInt().compareUnsigned( b.toUInt())
95+ operator fun compareTo (b : Int ) = toInt().compareUnsigned( b)
9396}
0 commit comments