scalb() double in Java

scalb(): This method is available in the Math class of Java.

Syntax:

double java.lang.Math.scalb(double d, int scaleFactor)

This method has two arguments one of type double and another of type int as its parameters. This method returns d ×2scaleFactor rounded as if performed by a single correctly rounded floating-point multiply to a member of the double value set.

Note:

1. If the exponent of the result is between Double.MIN_EXPONENT and Double.MAX_EXPONENT, the answer is calculated exactly. 

2. If the exponent of the result would be larger than Double.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.

d: number to be scaled by a power of two.scaleFactor power of 2 used to scale d

Returns: d × 2scaleFactor.

For Example:

Math.scalb(19.82,5) = > It returns 634.24

Approach

Java

public class ScalbDouble {
    public static void main(String[] args) {

        double d = 19.82;
        int scaleFactor = 5;
        System.out.println(Math.scalb(d, scaleFactor));

    }
}

Output:

634.24

No comments:

Post a Comment