passeraを使って以下のように書けますけど、ULongが-値になってしまったりします。
Passera: https://github.com/nystrom/scala-unsigned
import passera.unsigned._
import passera.numerics._
object Short {
def apply(a:Int):Short = a.toShort
def apply(a:UInt):Short = a.toShort
def apply(a:Long):Short = a.toShort
def apply(a:ULong):Short = a.toShort
}
object UShort {
def apply(a:UByte):UShort = a.toUShort
def apply(a:UInt):UShort = a.toUShort
def apply(a:ULong):UShort = a.toUShort
def apply(a:Int):UShort = a.toUShort
def apply(a:Long):UShort = a.toUShort
}
object Long {
def apply(a:Int):Long = a.toLong
def apply(a:UInt):Long = a.toLong
def apply(a:ULong):Long = a.toLong
}
object ULong {
def apply(a:UInt):ULong = a.toULong
def apply(a:ULong):ULong = a.toULong
def apply(a:Int):ULong = a.toULong
def apply(a:Long):ULong = a.toULong
}
object t2 {
val zero = 0.toUInt
def main(args:Array[String]) {
println("short test")
println(UShort(0xffff))
println(UShort(UShort(0xffff)+UShort(0xffff)).toHexString)
println(Short(Short(0xffff)+Short(0xffff)))
println(Short(UShort(UShort(0xffff)+UShort(0xffff))))
println(Short(111L))
println(ULong(0x7fffffffffffffffL).toString)
println(ULong(0x8000000000000000L).toString)
println(ULong(0xffffffffffffffffL).toString)
}
}