Saturday, November 15, 2025
HomeLanguagesJavaStrictMath scalb() Method in Java

StrictMath scalb() Method in Java

  1. The scalb(double num, int scale) is an inbuilt method of StrictMath class in Java which is used to calculate num * 2^scale and rounded as performed by a single correctly rounded floating point multiplied to a member of the double value argument.
    • The result is calculated accurately when the exponent of the result is between Double.MIN_EXPONENT and Double.MAX_EXPONENT.
    • An infinity is returned when the exponent of the result is greater than Double.MAX_EXPONENT.
    • When the result is subnormal then the correctness may be lost which means when scalb(num, scale) is subnormal, scalb(scalb(num, scale), -scale) may not equal num.
    • The result is NaN when the num is NaN
    • The result is an infinity of the same sign of num when num is infinite
    • The result will be a zero of the same sign when the num is zero.

    Syntax:

    public static double scalb(double num, int scale)

    Parameters: The method accepts two parameter:

    • num : This is of double type and refers to number to be scaled by a power of 2.
    • scalb : This is of integer type and refers to the power of 2 used to scale num.

    Return Value : The method returns the num × 2^scale.

    Examples :

    Input: num = 7
           scalb = 2
    Output: 28
    

    Below program illustrate the java.lang.StrictMath.scalb() method.




    // Java praogram to illustrate the
    // java.lang.StrictMath.scalb() 
    import java.lang.*;
      
    public class Geeks {
      
    public static void main(String[] args) {
      
        double num1 = 12 , num2 = -7.2, num3 = 0.0;
        int scalb = 2;
      
        double scalb_Value = StrictMath.scalb(num1, scalb); 
        System.out.println("Output = "+scalb_Value);
      
        scalb_Value = StrictMath.scalb(num2, scalb); 
        System.out.println("Output = " +scalb_Value);
      
        scalb_Value = StrictMath.scalb(num3, scalb); 
        System.out.println("Output = "+scalb_Value);
    }
    }

    
    
    Output:

    Output = 48.0
    Output = -28.8
    Output = 0.0
    
  2. The scalb(float num, int scale) is the inbuilt method of StrictMath class in Java to calculate num * 2^scale and rounded as performed by a single correctly rounded floating point multiplied to a member of the float value argument.
    • The result is calculated accurately when the exponent of the result is between Float.MIN_EXPONENT and Float.MAX_EXPONENT.
    • An infinity is returned when the exponent of the result greater than Float.MAX_EXPONENT.
    • When the result is subnormal then the correctness may be lost which means when scalb(num, scale) is subnormal, scalb(scalb(num, scale), -scale) may not equal num.
    • The result is NaN when the num is NaN
    • The result is an infinity of the same sign of num when num is infinite
    • The result will be a zero of the same sign when the num is zero.

    Syntax :

    public static float scalb(float num, int scale)

    Parameters: The method accepts two parameter:

    • num : This is of float type and refers to number to be scaled by a power of 2.
    • scalb : This is of integer type and refers to the power of 2 used to scale num.

    Return Value : The method returns the num × 2^scale.

    Examples :

    Input: num = 2.5f
           scalb = 4
    Output: 40.0
    

    Below program illustrate the java.lang.StrictMath.scalb() method.




    // Java praogram to illustrate the
    // java.lang.StrictMath.scalb() 
    import java.lang.*;
      
    public class Geeks {
      
    public static void main(String[] args) {
      
        float num1 = 8.3f, num2 = -4.2f, num3 = 0.0f;
        int scalb = 3;
      
        float scalb_Value = StrictMath.scalb(num1, scalb); 
        System.out.println("Output = "+scalb_Value);
      
        scalb_Value = StrictMath.scalb(num2, scalb); 
        System.out.println("Output = " +scalb_Value);
      
        scalb_Value = StrictMath.scalb(num3, scalb); 
        System.out.println("Output = "+scalb_Value);
    }
    }

    
    
    Output:

    Output = 66.4
    Output = -33.6
    Output = 0.0
    
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32401 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6768 POSTS0 COMMENTS
Nicole Veronica
11919 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11990 POSTS0 COMMENTS
Shaida Kate Naidoo
6897 POSTS0 COMMENTS
Ted Musemwa
7149 POSTS0 COMMENTS
Thapelo Manthata
6850 POSTS0 COMMENTS
Umr Jansen
6841 POSTS0 COMMENTS