LoginSignup
0
0

More than 5 years have passed since last update.

Scala Unsigned test

Posted at

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)
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0