gpt4 book ai didi

java - 如何在 Java 或 Groovy 中找到下一个 Double?

转载 作者:搜寻专家 更新时间:2023-11-01 01:03:47 26 4
gpt4 key购买 nike

当有一个 Double d 时,我想知道哪个 Double' 是比 d 大的最小可能值。

当 d==0 我知道答案时,那将是 Double.MIN_VALUE :

> 0d + Double.MIN_VALUE
4.9E-324

但是所有其他数字(例如 1d)呢?

> 1d + Double.MIN_VALUE
1.0

我想它必须与重要数字有关,但简而言之:我正在寻找一种方法来给我下一个双数

nextDouble(0)==4.9E-324

最佳答案

看看这些函数。

public static double nextAfter(double start, double direction)

Returns the floating-point number adjacent to the first argument in the direction of the second argument. If both arguments compare as equal the second argument is returned.

public static double nextUp(double d)

Returns the floating-point value adjacent to d in the direction of positive infinity. This method is semantically equivalent to nextAfter(d, Double.POSITIVE_INFINITY); however, a nextUp implementation may run faster than its equivalent nextAfter call.

关于java - 如何在 Java 或 Groovy 中找到下一个 Double?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22715536/

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