This page is no longer maintained — Please continue to the home page at www.scala-lang.org

implict objects for providing lower/ upper integer bounds for Int, Long?

No replies
Sciss
Joined: 2008-12-17,
User offline. Last seen 28 weeks 5 days ago.

hi,

is there any object (MinMax in the example) that provides the maximum positive values for integers (Int, Long)? like

object MyColl {
def empty[ A : Ordering : MinMax ] : MyColl[ A ] = new Impl[ A ]

private class Impl[ @specialized( Int, Long ) A ]( implicit ord: Ordering[ A ], minMax: MinMax[ A ]) {
def smallerThanMax( a: A ) : Boolean = ord.lt( a, minMax.max )
}
}
trait MyColl[ @specialized( Int, Long ) A ] {
def smallerThanMax( a: A ) : Boolean
}

so that minMax.min for Int gives Int.MinValue and for Long gives Long.MinValue, and minMax.max gives Int.MaxValue and Long.MaxValue respectively?

i see that Numeric has `one`, and `zero`, so i was wondering if something like `maxValue` and `minValue` also exist somewhere for integer types, preferably with implicits already set up?

thanks, -sciss-

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland