×

Java Math scalb() Method

The scalb() method of Java Math class returns a single perfectly rounded product of floating-point and member of the double value set as if performed by d*2scaleFacor rounded value.

Syntax:

  1. public static double scalb(double d, int scaleFactor)
  2. public static float scalb(float d,int scaleFactor)

Parameters:

The parameter ‘d’ represents the number to be scaled by a power of 2 and ‘scaleFactor’ represents power of 2 used to scale d.

Return Value:

The scalb() method computes the rounded value for d*2scaleFacor.

Example 1:

public class JavaMathScalbExample1 {
    static  int i=1;
    public static void main(String[] args) {
        double d=0.5d;
        int scaleFactor=9;
        //returns a single perfectly rounded product of floating-point
        System.out.println(i++ +". Value : " +Math.scalb(d,scaleFactor));
    }
}

Output:

Value : 256.0

Example 2:

public class JavaMathScalbExample2 {
    static  int i=1;
    public static void main(String[] args) {
        double d=2;
        int scaleFactor=0;
        //returns d if the scaleFactor's value is 0
        System.out.println(i++ +". Value : " +Math.scalb(d,scaleFactor));
    }
}

Output:

Value : 2.0

Example 3:

public class JavaMathScalbExample3 {
    static  int i=1;
    public static void main(String[] args) {
        double d=Double.NaN;
        int scaleFactor=Integer.MIN_VALUE;
        //returns NaN, if either argument is NaN
        System.out.println(i++ +". Value : " +Math.scalb(d,scaleFactor));
    }
}

Output:

Value : NaN

Example 4:

public class JavaMathScalbExample4{
    static  int i=1;
    public static void main(String[] args) {
        double d=Double.POSITIVE_INFINITY;
        int scaleFactor=1;
        //returns Infinity, if d is Infinite
        System.out.println(i++ +". Value : " +Math.scalb(d,scaleFactor));
    }
}

Output:

Value : Infinity

Example 5:

public class JavaMathScalbExample5 {
    static  int i=1;
    public static void main(String[] args) {
        float d=Float.NEGATIVE_INFINITY;
        int scaleFactor=1;
        //returns NEGATIVE Infinity, if d is NEGATIVE Infinite
        System.out.println(i++ +". Value : " +Math.scalb(d,scaleFactor));
    }
}

Output:

Value : -Infinity

Related Topics

How to declare string array in Java

Introduction Array is a data structure with a fixed size, which allows us to store elements of similar type. Data of primitive types like int, char, float, string, etc. can be...

2 minutes read.

Java Class Methods

Methods called on a class rather than a specific object instance are known as class methods. The static modifier guarantees uniform implementation across all instances of the class. Syntax public class NameOfClass...

3 minutes read.

Concurrent Modification Exception In Java

When an object is attempted to be updated concurrently when it is not allowed, the ConcurrentModificationException arises. This error typically occurs while using Java Collection classes. When another thread is iterating...

5 minutes read.

Lazy Propagation in Segment Tree in Java

The topic of segment trees in Java is continued by the topic of sluggish propagation in segment trees. It is suggested that readers first read through the section tree topic....

4 minutes read.

Frugal number in Java

A frugal number is a positive integer with base b that has more digits than the number of prime factors it can be factored into (including exponents greater than 1)....

3 minutes read.

How to initialize string array in Java

In this tutorial, we will learn how the string array is initialized in java. The initialization of string array in the java by using the NEW (it creates the object for...

3 minutes read.

Upcasting in Java

To know what is Upcasting in Java we should first equip ourselves about what is casting or type casting in Java. Casting The process of providing or replacing a reference variable of...

3 minutes read.

Pangram Program in Java

If a string comprises all alphabet letters from A to Z or from a to z without regard to case, it is referred to as a pangram. Some examples of pangram...

3 minutes read.

GCD Program in Java

GCD Program in Java The GCD program in Java outputs the GCD of the given numbers. In mathematics, Greatest Common Divisor (GCD), Greatest Common Factor or Highest Common Factor (HCF) of...

14 minutes read.

Normal and Trace of a Matrix in Java

Normal of a matrix The square root of the total squares of each element in a matrix is known as the matrix's normal. Think of the following matrix as an example. Example: [[1,2,3]  ...

3 minutes read.

Singleton Design Pattern in Java

In the singleton pattern, a class that only has one instance and offers a universal point of access is taken into consideration. It can also be defined in another way, a...

4 minutes read.

How to Convert long to int in Java

How to Convert long to int in Java When we assign a larger type value to a variable of smaller type, then we need to perform explicit casting for the conversion....

2 minutes read.

Java Stringjoiner Class

StringJoiner is a class which is used to construct a sequence of characters which are separated by a delimiter. Optionally, it starts with a provided prefix and ended with the...

5 minutes read.

Java Delete File

There are two techniques to erase a record in Java: Utilizing File.delete() technique.Utilizing File.deleteOnExit() technique. Using File.delete() technique: In Java, we can erase a document by utilizing the File.delete() technique for File class....

2 minutes read.

Segment Tree in Java

Binary trees can address a variety of issues; however, the Segment Tree is more efficient in terms of time complexity. The segment tree in Java is represented using an array. Native...

4 minutes read.

Java time local date

Java: Java is one of the programming language which is object oriented. It consists of many features such as robust, simple, architecture neutral, dynamic, distributed, multi threaded, portable etc. The main feature...

3 minutes read.

Bellman Ford Algorithm in Java

Numerous algorithms have been used in dynamic programming to determine the shortest path inside a graph. Among them are Floyd, all-pair shortest path problem, Breadth First Search, Depth First Search,...

6 minutes read.

Packages Program in java

Let us know what package is in the Java programming language, and later we will learn about types of packages and how to define a package. How to import Java...

4 minutes read.

How to Convert Binary to Decimal in Java

How to Convert Binary to Decimal in Java There are two methods to convert binary to decimal. Using Integer.parseInt() method Using user-defined logic Using Integer.parseInt() method The parseInt() is a static method of...

2 minutes read.

How to Convert int to double in Java

How to Convert int to double in Java When two variables of different types are involved in the single expression, Java compiler uses built-in library function to convert the variable to...

2 minutes read.