Java.lang Package Classes

Java Math - scalb() Method



The java.lang.Math.scalb() method returns a x 2b. If the exponent of the result is between Float.MIN_EXPONENT and Float.MAX_EXPONENT, the result is calculated exactly. In special cases it returns the following:

  • If the first argument is NaN, NaN is returned.
  • If the first argument is infinite, then an infinity of the same sign is returned.
  • If the first argument is zero, then a zero of the same sign is returned.

Syntax

public static float scalb(float a, int b)

Parameters

a Specify value to be scaled by power of 2.
b Specify power of 2 used to scale a.

Return Value

Returns a x 2b.

Exception

NA.

Example:

In the example below, scalb() method returns a x 2b.

import java.lang.*;

public class MyClass {
 public static void main(String[] args) {
  System.out.println(Math.scalb(2.55f, 4)); 
  System.out.println(Math.scalb(10f, 3));   
 }
}

The output of the above code will be:

40.8
80.0

❮ Java.lang - Math