![]() |
VOOZH | about |
In Java, the Math.getExponent() method returns the exponent of the floating-point number in its binary scientific notation. In this article, we are going to discuss how this method works for regular values and for special cases such as infinity and NaN.
Note: This method works withboth double and float types also, the number is represented in binary format, and this method gives us the exponent part of the binary representation.
Special Cases:
These special cases make sure that the Math.getExponent() methods work correctly.
public static int getExponent(double d)
Now, we are going to discuss some examples for better understanding.
Example 1: In this example, we will see the basic usage of getExponent() method.
Exponent of 12345.67: 13 Exponent of 1.23E-7: -23 Exponent of 1000000.0: 19
Example 2: In this example, we will see how getExponent() method handles NaN and Infinity.
Exponent of NaN: 1024 Exponent of Infinity: 1024
Explanation: Here, we are handling the cases like NaN and Infinity. For NaN it is returning 1024 and for Infinity it is returning 1024.
Important Points: