Java Double類的doubleToRawLongBits()方法是Java中的內置函數,該函數根據保留Not-a-Number(NaN)值的IEEE 754浮點“double format”位布局返回指定浮點值的表示形式。
用法:
public static long doubleToRawLongBits(double val)
參數:該方法僅接受一個參數val,該參數指定雙精度浮點數。
返回值:該函數返回代表浮點數的位。以下是特殊情況:
- 如果參數為正無窮大,則結果為7ff0000000000000L。
- 如果參數為負無窮大,則結果為0xfff0000000000000L。
- 如果參數為NaN,則結果為0x7ff8000000000000L。
以下程序說明了Double.doubleToRawLongBits()方法的使用:
示例1:
// Java program to demonstrate
// Double.doubleToLongBits() method
import java.lang.*;
class Gfg1 {
public static void main(String args[])
{
double val = 1.5d;
// function call
long answer = Double.doubleToRawLongBits(val);
// print
System.out.println(val + " in raw long bits: "
+ answer);
}
}
輸出:
1.5 in raw long bits: 4609434218613702656
示例2:
// Java program to demonstrate
// Double.doubleToRawLongBits() method
import java.lang.*;
class Gfg1 {
public static void main(String args[])
{
double val = Double.POSITIVE_INFINITY;
double val1 = Double.NEGATIVE_INFINITY;
double val2 = Double.NaN;
// function call
long answer = Double.doubleToRawLongBits(val);
// print
System.out.println(val + " in raw long bits: "
+ answer);
// function call
answer = Double.doubleToRawLongBits(val1);
// print
System.out.println(val1 + " in raw long bits: "
+ answer);
// function call
answer = Double.doubleToRawLongBits(val2);
// print
System.out.println(val2 + " in raw long bits: "
+ answer);
}
}
輸出:
Infinity in raw long bits: 9218868437227405312 -Infinity in raw long bits: -4503599627370496 NaN in raw long bits: 9221120237041090560
參考: https://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#doubleToRawLongBits(double)
相關用法
- Java Doubles.indexOf(double[] array, double[] target)用法及代碼示例
- Java Doubles.indexOf(double[] array, double target)用法及代碼示例
- Java Double compare()用法及代碼示例
- Java Double doubleValue()用法及代碼示例
- Java Double.compareTo()用法及代碼示例
- Java Double.equals()用法及代碼示例
- Java Double intValue()用法及代碼示例
- Java Double shortValue()用法及代碼示例
- Java Double byteValue()用法及代碼示例
- Java OptionalDouble of(double)用法及代碼示例
- Java Double parseDouble()用法及代碼示例
- Java Double hashCode()用法及代碼示例
- Java Double doubleToLongBits()用法及代碼示例
- Java Double isNaN()用法及代碼示例
- Java Double isInfinite()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Double doubleToRawLongBits() method in Java with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。