scalb(): This method is available in the Math class of Java.
Syntax:
float java.lang.Math.scalb(float f, int scaleFactor)
This method takes two arguments, one of type float and another of type int as its parameter. This method returns f ×2scaleFactor rounded as if performed by a single correctly rounded floating-point multiply to a member of the float value set.
Note:
1. If the exponent of the result is between Float.MIN_EXPONENT and Float.MAX_EXPONENT, the answer is calculated exactly.
2. If the exponent of the result would be larger than Float.MAX_EXPONENT, an infinity is returned.
Special cases:
1. If the first argument is NaN, NaN is returned.
2. If the first argument is infinite, then an infinity of the same sign is returned.
3. If the first argument is zero, then a zero of the same sign is returned.
Parameters: Two parameters are required for this method.
f: number to be scaled by a power of two.
scaleFactor: the power of 2 used to scale f.
Returns: f × 2scaleFactor.
For Example:
Math.scalb(19.8,4) = > It returns 316.8
Approach
Java
public class ScalbFloat {public static void main(String[] args) {float f = (float) 19.8;int scaleFactor = 4;System.out.println(Math.scalb(f, scaleFactor));}}
Output:
316.8
No comments:
Post a Comment