What is floorDiv() in scala?

floorDiv() is a function of the math package in scala that returns the largest value less than or equal to the algebraic quotient.

Syntax


def floorDiv(x: Long, y: Long): Long

OR


def floorDiv(x: Int, y: Int): Int

Parameters

  • x is the dividend value.

  • y is the divisor value.

Return value

The function returns the largest value less than or equal to the algebraic quotient. The return type of the function is either Int or Long.


The function throws ArithmeticException if y is 0.

Code

object MainObject {
def main(args: Array[String]) {
println(s"Math.floorDiv(-15, 5) = ${Math.floorDiv(-15, 5)}");
println(s"Math.floorDiv(29, 6) = ${Math.floorDiv(29, 6)}");
// ArthimeticException will be thrown at line 6
println(s"Math.floorDiv(29, 0) = ${Math.floorDiv(29, 0)}");
}
}

Free Resources