Java.lang.StrictMath.scalb() Method
Advertisements
Description
The java.lang.StrictMath.scalb(float f, int scaleFactor) method returns d × 2scaleFactor rounded as if performed by a single correctly rounded floating-point multiply to a member of the float value set.It include these cases:
- 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 retrned.
Declaration
Following is the declaration for java.lang.StrictMath.scalb() method
public static float scalb(float f, int scaleFactor)
Parameters
d -- This is the number to be scaled by a power of two.
scaleFactor -- This is the power of 2 used to scale f.
Return Value
This method returns d × 2scaleFactor
Exception
NA
Example
The following example shows the usage of java.lang.StrictMath.scalb() method.
package com.tutorialspoint;
import java.lang.*;
public class StrictMathDemo {
public static void main(String[] args) {
float f1 = 5.0f , f2 = 9.56f, f3 = 0.0f;
int power = 2;
// returns (First argument*(pow(second argument,2) i.e d × 2scaleFactor
float scalbValue = StrictMath.scalb(f1 , power);
System.out.println("value = " + scalbValue1);
scalbValue = StrictMath.scalb(f2 , power);
System.out.println("value = " + scalbValue1);
scalbValue = StrictMath.scalb(f3 , power);
System.out.println("value = " + scalbValue1);
}
}
Let us compile and run the above program, this will produce the following result:
value = 20.0 value = 38.24 value = 0.0