gpt4 book ai didi

java - 为什么当两个值都是 double 时没有 ArithmeticException(除以零)?

转载 作者:太空狗 更新时间:2023-10-29 15:34:53 25 4
gpt4 key购买 nike

<分区>

看过Double.java的源码和一些常量是这样的

/**
* Constant for the Not-a-Number (NaN) value of the {@code double} type.
*/
public static final double NaN = 0.0 / 0.0;

/**
* Constant for the positive infinity value of the {@code double} type.
*/
public static final double POSITIVE_INFINITY = 1.0 / 0.0;

/**
* Constant for the negative infinity value of the {@code double} type.
*/
public static final double NEGATIVE_INFINITY = -1.0 / 0.0;

但我想知道为什么它不抛出 ArithmeticException(除以零)?

我试过了

 public static final int VALUE = 0/0;

现在它抛出异常但是当我说

 public static final double VALUE = 0d/0d;

它没有抛出异常...

Double 的魔力是什么?为什么它不抛出异常?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com