Scala Tutorial Scala References

Scala - Math IEEEremainder() Method



The Scala Math IEEEremainder() method is used to compute the remainder operation on two arguments as prescribed by the IEEE 754 standard. In special cases it returns the following:

  • If either argument is NaN, or the first argument is infinite, or the second argument is zero, then the result is NaN.
  • If the first argument is finite and the second argument is infinite, then the result is the same as the first argument.

Syntax

def IEEEremainder(x: Double, y: Double): Double = 
                      java.lang.Math.IEEEremainder(x, y)

Parameters

x Specify the dividend.
y Specify the divisor.

Return Value

Returns the remainder when x is divided by y.

Exception

NA.

Example:

In the example below, IEEEremainder() method is used to calculate the remainder operation on two given arguments.

import scala.math._

object MainObject {
  def main(args: Array[String]) {
    println(s"IEEEremainder(23, 4) = ${IEEEremainder(23, 4)}");   
    println(s"IEEEremainder(23, -4) = ${IEEEremainder(23, -4)}"); 
    println(s"IEEEremainder(-23, 4) = ${IEEEremainder(-23, 4)}"); 
    println(s"IEEEremainder(-23, -4) = ${IEEEremainder(-23, -4)}"); 
    println(s"IEEEremainder(Double.NaN, 5) = ${IEEEremainder(Double.NaN, 5)}"); 
    println("IEEEremainder(Double.PositiveInfinity, 20) = "
            + IEEEremainder(Double.PositiveInfinity, 20));
  }
}

The output of the above code will be:

IEEEremainder(23, 4) = -1.0
IEEEremainder(23, -4) = -1.0
IEEEremainder(-23, 4) = 1.0
IEEEremainder(-23, -4) = 1.0
IEEEremainder(Double.NaN, 5) = NaN
IEEEremainder(Double.PositiveInfinity, 20) = NaN

❮ Scala - Math Methods