- The scalb(double a, int scale ) is an inbuilt method of Math class in Java which is used to get the value a x 2^scale . The result is accurately calculated when the exponent of the result is between Double.MIN_EXPONENT and Double.MAX_EXPONENT. It gives rise to four special results:
- It returns an infinity when the exponent of the result is larger than Double.MAX_EXPONENT.
- The result is NaN when the first argument is NaN.
- The result is an infinity of the same sign when the first argument is infinite.
- It returns a Zero of the same sign when the first argument is zero.
Syntax :
public static double scalb(double a, int scale)
Parameters : This method accepts two parameters they are:
- a: This is of the double type which is the number to be scaled by a power of two.
- scale: This is of integer type which is the power of 2 ,used to scale a
Return Value : The method returns a x 2^scale
Examples :Input: a = 77.23 scale = 3 Output = 617.84
Below program illustrates the java.lang.Math.scalb(double a, int scale) method:
// Java praogram to illustrate the// java.lang.Math.scalb(double a, int scale )importjava.lang.*;ÂÂpublicclassGeeks {   Âpublicstaticvoidmain(String[] args)   Â{       Âdoublep =52.12;       Âintscale =8;       Â// It returns p x 2^scale       ÂSystem.out.print("Value of Math.scalb("                    Â+ p +", "+ scale +") = ");       ÂSystem.out.println(Math.scalb(p, scale));   Â}}Output:Value of Math.scalb(52.12, 8) = 13342.72
- The java.lang.Math.scalb(float a, int scale ) is an inbuilt method which returns a x 2^scale . The result is accurately calculated when the exponent of the result is between Float.EXPONENT and Float.MAX_EXPONENT.
- It returns an infinity when the exponent of the result is larger than Float.MAX_EXPONENT.
- The result is NaN when the first argument is NaN.
- The result is an infinity of the same sign when the first argument is infinite.
- It returns a Zero of the same sign when the first argument is zero.
Syntax :
public static double scalb(float a, int scale)
Parameters : This method accepts two parameters:
- a: This is of float type which is the number to be scaled by a power of two.
- scale: This is of integer type which refers to the power of 2 used in scaling of a
Return Value : The method returns a x 2^scale
Examples :Input: a = 32.14f scale = 6 Output = 2056.96
Below program illustrates the java.lang.Math.scalb(float a, int scale ) method:
Program 1:// Java praogram to illustrate the// java.lang.Math.scalb(float a, int scale )importjava.lang.*;ÂÂpublicclassGeeks {   Âpublicstaticvoidmain(String[] args)   Â{       Âfloatp =81.27f;       Âintscale =8;       Â// Calculate p multiplied by 2 raised in scale       ÂSystem.out.print("Value of Math.scalb("+                           Âp +", "+ scale +") = ");       ÂSystem.out.println(Math.scalb(p, scale));   Â}}Output:Value of Math.scalb(81.27, 8) = 20805.12
