- 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: 28Below program illustrate the java.lang.StrictMath.scalb() method.
// Java praogram to illustrate the// java.lang.StrictMath.scalb()Âimportjava.lang.*;ÂÂpublicclassGeeks {ÂÂpublicstaticvoidmain(String[] args) {ÂÂÂ Â Â Âdoublenum1 =12, num2 = -7.2, num3 =0.0;Â Â Â Âintscalb =2;ÂÂÂ Â Â Âdoublescalb_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
- 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.0Below program illustrate the java.lang.StrictMath.scalb() method.
// Java praogram to illustrate the// java.lang.StrictMath.scalb()Âimportjava.lang.*;ÂÂpublicclassGeeks {ÂÂpublicstaticvoidmain(String[] args) {ÂÂÂ Â Â Âfloatnum1 =8.3f, num2 = -4.2f, num3 =0.0f;Â Â Â Âintscalb =3;ÂÂÂ Â Â Âfloatscalb_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
