Scala Tutorial Scala References

Scala - Math getExponent() Method



The Scala Math getExponent() method returns the unbiased exponent used in the representation of argument. The method can be overloaded and it can take Float and Double arguments.

Syntax

def getExponent(x: Float): Int = java.lang.Math.getExponent(x)
def getExponent(x: Double): Int = java.lang.Math.getExponent(x)

Parameters

x Specify a value.

Return Value

Returns the unbiased exponent used in the representation of argument.

Exception

NA.

Example:

In the example below, Math.getExponent() method returns the unbiased exponent used in the representation of argument.

object MainObject {
  def main(args: Array[String]) {
    println(s"Math.getExponent(10) = ${Math.getExponent(10)}"); 
    println(s"Math.getExponent(100) = ${Math.getExponent(100)}"); 
    println(s"Math.getExponent(500) = ${Math.getExponent(500)}"); 
    println(s"Math.getExponent(1050) = ${Math.getExponent(1050)}");     
  }
}

The output of the above code will be:

Math.getExponent(10) = 3
Math.getExponent(100) = 6
Math.getExponent(500) = 8
Math.getExponent(1050) = 10

❮ Scala - Math Methods