Float类floatToRawIntBits()方法 (Float class floatToRawIntBits() method)
floatToRawIntBits() method is available in java.lang package.
floatToRawIntBits()方法在java.lang包中可用。
floatToRawIntBits() method follows IEEE 754 single-precision floating-point standards and according to standards, it returns the bits that denote floating-point value along with preserving NaN value.
floatToRawIntBits()方法遵循IEEE 754单精度浮点标准,并且根据标准,它返回表示浮点值的位以及保留NaN值。
floatToRawIntBits() method is a static method, it is accessible with the class name too and, if we try to access the method with the class object then also we will not get an error.
floatToRawIntBits()方法是一个静态方法,也可以使用类名进行访问,而且,如果尝试使用类对象访问该方法,那么也不会出错。
floatToRawIntBits() method does not throw an exception at the time of representing bits along with preserving NaN (Not a Number).
floatToRawIntBits()方法在表示位以及保留NaN (非数字)时不会引发异常。
Syntax:
句法:
public static int floatToRawIntBits(float f);
Parameter(s):
参数:
float f – represents the single precision floating point value.
float f –表示单精度浮点值。
Return value:
返回值:
The return type of this method is float, it returns the bits that represent the single precision floating-point value.
此方法的返回类型为float ,它返回表示单个精度浮点值的位。
If we pass "positive infinity", it returns the value "0x7f800000".
如果我们传递“ positive infinity” ,它将返回值“ 0x7f800000” 。
If we pass "negative infinity", it returns the value "0xff800000".
如果我们传递“负无穷大” ,它将返回值“ 0xff800000” 。
If we pass "NaN", it returns the actual NaN values (i.e. it does not collapse all the bit encoding a NaN to a "basic" NaN value).
如果我们传递“ NaN” ,它将返回实际的NaN值(即,它不会将编码NaN的所有位折叠为“基本” NaN值)。
Example:
例:
// Java program to demonstrate the example
// of floatToRawIntBits (float f)
// method of Float class
public class FloatToRawIntBits {
public static void main(String[] args) {
// Variables initialization
float value1 = 18.20f;
float value2 = 19.20f;
// Display value1,value2 values
System.out.println("value1: " + value1);
System.out.println("value2: " + value2);
// It returns the bits denoted by the single precision
// floating point argument by calling
// Float.floatToRawIntBits(value1)
int result1 = Float.floatToRawIntBits(value1);
// It returns the bits denoted by the single precision
// floating point argument by calling
// Float.floatToRawIntBits(value2)
int result2 = Float.floatToRawIntBits(value2);
// Display result1,result2 values
System.out.println("Float.floatToRawIntBits(value1): " + result1);
System.out.println("Float.floatToRawIntBits(value2): " + result2);
System.out.print("Float.floatToRawIntBits(NaN): ");
System.out.println(Float.floatToRawIntBits(5.0f % 0f));
}
}
Output
输出量
value1: 18.2
value2: 19.2
Float.floatToRawIntBits(value1): 1100061082
Float.floatToRawIntBits(value2): 1100585370
Float.floatToRawIntBits(NaN): 2143289344
翻译自: https://www.includehelp.com/java/float-class-floattorawintbits-method-with-example.aspx