当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Double longBitsToDouble()用法及代码示例


Java Double 类的 longBitsToDouble() 方法返回等同于已确认位表示的双精度值。

结果是:

  1. 正无穷大,如果传递的参数是 0x7ff0000000000000L。
  2. 负无穷大,如果传递的参数是 0x7ff0000000000000L。

用法

public static double longBitsToDouble(long bits)

参数

bits -是传递的长整数。

返回值

longBitsToDouble() 方法返回具有相同位模式的 double 类型的浮点值。

例子1

public class Double_longBitsToDoubleMethodExample1 {
    public static void main(String[] args) {

             int value1=76767127;

             Double d1=Double.longBitsToDouble(value1);
             System.out.println("Float value after conversion = "+d1);

             int value2=48667;
             //method can be called directly in println function
             System.out.println("Float value after conversion = "+Double.longBitsToDouble(value2));

             //passing negative integer
             int value3=-4756;
        System.out.println("Float value after conversion = "+Double.longBitsToDouble(value3));


    }
}

输出:

Float value after conversion = 3.7928E-316
Float value after conversion = 2.40447E-319
Float value after conversion = NaN

例子2

public class Double_longBitsToDoubleMethodExample2 {


    public static void main(String[] args) {


      //result returned is positive infinity

       int value1=  0X7f800000;

        System.out.println("1. "+value1+ " value = "+Double.longBitsToDouble(value1));

        // result returned is negative infinity

        int value2=0Xff800000;

        System.out.println("2. "+value1+ " value = "+Double.longBitsToDouble(value2));


        int value3 =Integer.MAX_VALUE;

        System.out.println("3. "+value3 + " value = " +Double.longBitsToDouble(value3));


        int value4 =Integer.MIN_VALUE;

        System.out.println("4. "+ value4 + " value = " +Double.longBitsToDouble(value4));

}

}

输出:

1. 2139095040 value = 1.0568533725E-314
2. 2139095040 value = NaN
3. 2147483647 value = 1.060997895E-314
4. -2147483648 value = NaN

例子3

import java.util.Scanner;

public class Double_longBitsToDoubleMethodExample3 {

    public static void main(String[] args) {


        Scanner scanner = new Scanner(System.in);

        System.out.println("Enter first integer:");

        int value1=scanner.nextInt();

        System.out.println("1. Double value = "+Double.longBitsToDouble(value1));


        System.out.println("\nEnter Second negative integer");

        int value2=scanner.nextInt();

        if(value2<0) {

            System.out.println("2. Double value = " + Double.longBitsToDouble(value2));

        }

        else{

            System.err.println("plz re enter negative integer.");

        }

    }

}

输出:

Enter first integer:
648375
1. Double value = 3.2034E-318

Enter Second negative integer
-48755
2. Double value = NaN






相关用法


注:本文由纯净天空筛选整理自 Java Double longBitsToDouble() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。