Skip to content

Instantly share code, notes, and snippets.

@rightfold
Created October 17, 2014 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rightfold/88c711a431578ae51eb6 to your computer and use it in GitHub Desktop.
Save rightfold/88c711a431578ae51eb6 to your computer and use it in GitHub Desktop.
scala> class UInt(val signedValue: Int) extends AnyVal {
| def +(other: UInt) = new UInt(signedValue + other.signedValue)
| def -(other: UInt) = new UInt(signedValue - other.signedValue)
| def *(other: UInt) = new UInt(signedValue * other.signedValue)
| def /(other: UInt) = new UInt(Integer.divideUnsigned(signedValue, other.signedValue))
|
| override def toString = Integer.toUnsignedString(signedValue)
| }
defined class UInt
scala> new UInt(1) - new UInt(2)
res1: UInt = 4294967295
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment