strictmath
StrictMath类的getExponent()方法 (StrictMath Class getExponent() method)
Syntax:
句法:
public static int getExponent(float fl);
public static int getExponent(double do);
getExponent() method is available in java.lang package.
getExponent()方法在java.lang包中可用。
getExponent(float fl) method is used to return the unbiased exponent used in the denotation of the given argument(i.e. the argument is of float type).
getExponent(float fl)方法用于返回在给定参数的表示中使用的无偏指数(即,该参数为float类型)。
getExponent(double do) method is used to return the unbiased exponent used in the denotation of the given argument(i.e. the argument is of double type).
getExponent(double do)方法用于返回在给定参数的表示中使用的无偏指数(即,该参数为double类型)。
These methods don't throw an exception.
这些方法不会引发异常。
These are static methods, it is accessible with the class name and, if we try to access these methods with the class object then we will not get any error.
这些是静态方法,可以通过类名进行访问,如果尝试使用类对象访问这些方法,则不会出现任何错误。
Parameter(s):
参数:
float / double – represents the float/double type value whose unbiased exponent to be found.
float / double-表示要找到其无偏指数的float / double类型值。
Return value:
返回值:
The return type of this method is int / double – it returns the unbiased exponent of the given argument and the argument value is of double type.
此方法的返回类型为int / double-返回给定参数的无偏指数,并且参数值为double类型。
Note:
注意:
If we pass NaN as an argument, method returns (Float.MAX_EXPONENT +1) / (Double.MAX_EXPONENT +1).
如果将NaN作为参数传递,则方法返回(Float.MAX_EXPONENT +1)/(Double.MAX_EXPONENT +1)。
If we pass an infinity (positive or negative), method returns (Float.MAX_EXPONENT) / (Double.MAX_EXPONENT).
如果传递无穷大(正数或负数),则方法返回(Float.MAX_EXPONENT)/(Double.MAX_EXPONENT)。
If we pass a zero (0), method returns (Float.MIN_EXPONENT - 1) / (Double.MIN_EXPONENT - 1).
如果我们传递零(0),则方法返回(Float.MIN_EXPONENT-1)/(Double.MIN_EXPONENT-1)。
Example:
例:
// Java program to demonstrate the example
// of getExponent() method of StrictMath class
public class GetExponent {
public static void main(String[] args) {
// variable declarations
float f1 = 7.0f / 0.0f;
float f2 = -7.0f / 0.0f;
float f3 = 0.0f;
float f4 = -0.0f;
float f5 = 12485.2f;
double d1 = 7.0 / 0.0;
double d2 = -7.0 / 0.0;
double d3 = 0.0;
double d4 = -0.0;
double d5 = 12485.2;
// Display previous value of f1,f2,f3,f4 and f5
System.out.println("f1: " + f1);
System.out.println("f2: " + f2);
System.out.println("f3: " + f3);
System.out.println("f4: " + f4);
System.out.println("f5: " + f5);
// Display previous value of d1,d2,d3,d4 and d5
System.out.println("d1: " + d1);
System.out.println("d2: " + d2);
System.out.println("d3: " + d3);
System.out.println("d4: " + d4);
System.out.println("d5: " + d5);
System.out.println();
System.out.println("getExponent(float): ");
// Here , we will get (Float.MAX_EXPONENT) because we are
// passing parameter whose value is (infinity)
System.out.println("StrictMath.getExponent(f1): " + StrictMath.getExponent(f1));
// Here , we will get (Float.MAX_EXPONENT) because we are
// passing parameter whose value is (-infinity)
System.out.println("StrictMath.getExponent(f2): " + StrictMath.getExponent(f2));
// Here , we will get (Float.MIN_EXPONENT - 1) because we are
// passing parameter whose value is (0.0f)
System.out.println("StrictMath.getExponent(f3): " + StrictMath.getExponent(f3));
// Here , we will get (Float.MIN_EXPONENT - 1) because we are
// passing parameter whose value is (-0.0f)
System.out.println("StrictMath.getExponent(f4): " + StrictMath.getExponent(f4));
// Here , we will get unbiased exponent because we are
// passing parameter whose value is (12485.2f)
System.out.println("StrictMath.getExponent(f5): " + StrictMath.getExponent(f5));
System.out.println();
System.out.println("getExponent(double): ");
// Here, we will get (Double.MAX_EXPONENT) because we are
// passing parameter whose value is (infinity)
System.out.println("StrictMath.getExponent(d1): " + StrictMath.getExponent(d1));
// Here , we will get (Double.MAX_EXPONENT) because we are
// passing parameter whose value is (-infinity)
System.out.println("StrictMath.getExponent(d2): " + StrictMath.getExponent(d2));
// Here , we will get (Double.MIN_EXPONENT - 1) because we are
// passing parameter whose value is (0.0)
System.out.println("StrictMath.getExponent(d3): " + StrictMath.getExponent(d3));
// Here , we will get (Double.MIN_EXPONENT - 1) because we are
// passing parameter whose value is (-0.0)
System.out.println("StrictMath.getExponent(d4): " + StrictMath.getExponent(d4));
// Here , we will get unbiased exponent because we are
// passing parameter whose value is (12485.2)
System.out.println("StrictMath.getExponent(d5): " + StrictMath.getExponent(d5));
}
}
Output
输出量
f1: Infinity
f2: -Infinity
f3: 0.0
f4: -0.0
f5: 12485.2
d1: Infinity
d2: -Infinity
d3: 0.0
d4: -0.0
d5: 12485.2
getExponent(float):
StrictMath.getExponent(f1): 128
StrictMath.getExponent(f2): 128
StrictMath.getExponent(f3): -127
StrictMath.getExponent(f4): -127
StrictMath.getExponent(f5): 13
getExponent(double):
StrictMath.getExponent(d1): 1024
StrictMath.getExponent(d2): 1024
StrictMath.getExponent(d3): -1023
StrictMath.getExponent(d4): -1023
StrictMath.getExponent(d5): 13
翻译自: https://www.includehelp.com/java/strictmath-getexponent-method-with-example.aspx
strictmath