×

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 get ASCII value of char in Java

Introduction: On this application, you will learn how to find and show the ASCII value of char in Java. That is done with the use of type-casting and also everyday...

4 minutes read.

Java Switch Keyword

In this article we are going to learn the concept of a java switch keyword. Generally, java case keyword is used with the switch statements or keyword.Switch keyword is implemented in...

3 minutes read.

Java Boolean compare() method

The compare() method of Java Boolean class compares the specified Boolean values and returns a positive 1 or negative 1 or zero integer value based on the result. Syntax public static int...

2 minutes read.

Java TreeMap

TreeMap in Java with Example Java TreeMap implements the NavigableMap interface. It extends Map Interface. Java TreeMap is based on the red-black Tree implementation. It stores the key-value pair in sorted...

7 minutes read.

Java LDAP Authentication

WHAT IS LDAP? Clients can communicate with directory services by sending requests and receiving responses using the Lightweight Directory Access Protocol (LDAP). The term "LDAP server" refers to a directory service...

7 minutes read.

How to Convert boolean to String in Java

How to Convert boolean to String in Java There are two methods to convert boolean to String. Using valueOf(boolean) method Using toString(boolean) method For both the above methods, if the passes Boolean...

2 minutes read.

Hamming Code in Java

In a computer network, hamming code is a unique set of error-correction codes. It is mostly utilised in computer graphics for mistake detection and correction during data transmission from sender...

8 minutes read.

Java Regular Expressions

Java Regular Expressions The Java Regex or Regular Expression is an API that defines a pattern for searching or manipulating strings. A regular expression is a pattern that can be as simple as...

8 minutes read.

History and Evolution of Java

Java is invented by James Gosling, Patrick Naughton, Chris Warth, Ed Frank, and Mike Sheridan at Sun Microsystems, Inc. in 1991. Java is related to C++, which is inherited from...

3 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.

Difference between String, StringBuffer and StringBuilder in java

What is a string in Java? Strings are a collection of characters that are commonly used in Java programming. Strings are regarded as objects in the Java programming language. “String” is a...

4 minutes read.

How to check Date Null in Java?

In this section, we will be acknowledged about Date Null in Java. The date null in Java is an entity that is used when there is no specified value for...

3 minutes read.

Bottom view of a binary tree in Java

The lowest nodes in their horizontal distance are present and referred to as the bottom view of a binary tree. The horizontal distance between the nodes of a binary tree...

4 minutes read.

Group by in Java 8

By using this groupingBy() method, developers can directly able to perform the "GROUP BY" operation. The thing is, now, the Java 8 programming language allows the programmers to do this...

3 minutes read.

Java 16

Java 16 is the most recent short-term incremental release, based on Java 15, and it was released on March 16, 2021. Records and sealed classes are just two of the...

11 minutes read.

Java Try Keyword

The try block in Java is used to run essential code, such as connection closure, among other things. Whether an exception is resolved or not, the Java try block has...

3 minutes read.

Java Integer min() method

The min()  method of Integer class returns the smaller of two int values. It returns the same result as by calling Math.min.  Syntax public static int min(int a, int b) Parameters The parameters ‘a’...

2 minutes read.

Crown Pattern in Java

We know the importance of solving pattern problems. We can solve pattern problems by using any programming language. There is no rule to translating into a particular programming language. We...

4 minutes read.

Java Program to remove duplicate characters in a string

In strings, we can find many characters present one or more times in a string; accessing a particular character is difficult due to repetition. Duplicate characters will present in the...

5 minutes read.

Java Switch string

A multi-way branch statement is the switch statement. It offers a simple method for allocating execution to various code sections according to the expression's value. Primitive data types, including bytes,...

3 minutes read.