KissNumber is an alternative boxing for numeric variables in Scala.
What you need to know about KissNumber:
Numberis the parent type for both integer and floating point values.- An
IntegerNumberholds an integer value (it wraps aLong) - A
RealNumberholds a floating point value (it wraps aDouble) - All the operations that can be performed in a
Doublecan be performed in aRealNumber(including the existence of an implicitRichRealNumber) - All the operations that can be performed in a
Longcan be performed in aIntegerNumber(including the existence of an implicitRichIntegerNumber) except ...- the '/' operator performs a floating point division and ...
- a '/%' operator is provided instead, which returns a Pair containing the integer quotient and the modulus
- All the operations that
IntegerNumberandRealNumberhave in common can be performed directly on aNumber(including the existence of an implicitRichNumber). Hence thatIntegerNumberperforms floating point divisions. - Implicit bidirectional conversions between standard Scala values (
Int,Float,Double, ...) and the adequateNumbertypes are provided
import com.bryghts.kissnumber._
object Examples extends App
{
val n: Number = 3
def foo(x: Number, y: Number, z: Number): Number = x + y / z
val a: IntegerNumber = 1
val b: RealNumber = 2.3
val c: Number = 67
val d = foo(a, b, c)
println(d)
val l: List[Number] = List(1, 4.5, 2, 3, -2)
println(l.map{_ * 2}.mkString(","))
println(l.sorted.mkString(","))
}Maven Dependency:
<dependency>
<groupId>com.bryghts.kissnumber</groupId>
<artifactId>kissnumber_2.10</artifactId>
<version>0.0.3</version>
</dependency>Sbt Dependency:
libraryDependencies += "com.bryghts.kissnumber" % "kissnumber_2.10" % "0.0.3"