diff options
author | Paul Phillips <paulp@improving.org> | 2009-08-23 01:21:51 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-08-23 01:21:51 +0000 |
commit | 94e71c26a4a1d17dff3f6df74dd972c0280b655e (patch) | |
tree | 4925f57a62c2f2ed55d7e17bbb63ce7670fee991 | |
parent | cd36447b0af834fc6086acedf7625e513b9411d6 (diff) | |
download | scala-94e71c26a4a1d17dff3f6df74dd972c0280b655e.tar.gz scala-94e71c26a4a1d17dff3f6df74dd972c0280b655e.tar.bz2 scala-94e71c26a4a1d17dff3f6df74dd972c0280b655e.zip |
Numeric implementations for Short and Byte now ...
Numeric implementations for Short and Byte now that I'm hearing of the
occasional Numeric user.
-rw-r--r-- | src/library/scala/Numeric.scala | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/library/scala/Numeric.scala b/src/library/scala/Numeric.scala index e60b71120e..46259343fa 100644 --- a/src/library/scala/Numeric.scala +++ b/src/library/scala/Numeric.scala @@ -34,6 +34,36 @@ object Numeric { } implicit object IntIsIntegral extends IntIsIntegral with Ordering.IntOrdering + trait ShortIsIntegral extends Integral[Short] { + def plus(x: Short, y: Short): Short = (x + y).toShort + def minus(x: Short, y: Short): Short = (x - y).toShort + def times(x: Short, y: Short): Short = (x * y).toShort + def quot(x: Short, y: Short): Short = (x / y).toShort + def rem(x: Short, y: Short): Short = (x % y).toShort + def negate(x: Short): Short = (-x).toShort + def fromInt(x: Int): Short = x.toShort + def toInt(x: Short): Int = x.toInt + def toLong(x: Short): Long = x.toLong + def toFloat(x: Short): Float = x.toFloat + def toDouble(x: Short): Double = x.toDouble + } + implicit object ShortIsIntegral extends ShortIsIntegral with Ordering.ShortOrdering + + trait ByteIsIntegral extends Integral[Byte] { + def plus(x: Byte, y: Byte): Byte = (x + y).toByte + def minus(x: Byte, y: Byte): Byte = (x - y).toByte + def times(x: Byte, y: Byte): Byte = (x * y).toByte + def quot(x: Byte, y: Byte): Byte = (x / y).toByte + def rem(x: Byte, y: Byte): Byte = (x % y).toByte + def negate(x: Byte): Byte = (-x).toByte + def fromInt(x: Int): Byte = x.toByte + def toInt(x: Byte): Int = x.toInt + def toLong(x: Byte): Long = x.toLong + def toFloat(x: Byte): Float = x.toFloat + def toDouble(x: Byte): Double = x.toDouble + } + implicit object ByteIsIntegral extends ByteIsIntegral with Ordering.ByteOrdering + trait LongIsIntegral extends Integral[Long] { def plus(x: Long, y: Long): Long = x + y def minus(x: Long, y: Long): Long = x - y |