Currently I write some ugly code like
def div(dividend: Int, divisor: Int) = {
val q = dividend / divisor
val mod = dividend % divisor
In BigInt
, note /%
operation which delivers a pair with the division and the reminder (see API). Note for instance
scala> BigInt(3) /% BigInt(2)
(scala.math.BigInt, scala.math.BigInt) = (1,1)
scala> BigInt(3) /% 2
(scala.math.BigInt, scala.math.BigInt) = (1,1)
where the second example involves an implicit conversion from Int
to BigInt
.