3

根据 Wolfram Alpha 的说法,对于x > 2.

6.0/(x+16) > 2.0/(x+4)

为了获得最小的可能x,我正在使用numpy.nextafter().

>>> from numpy import nextafter
>>> x = nextafter(2,2+1)
>>> x
2.0000000000000004

然而。

>>> 6.0/(x+16) > 2.0/(x+4)
False

奇怪的是。

>>> x+1
3.0000000000000004
>>> x+4
6.0

那么我如何获得x > 2这种情况下的实际最小可能呢?

4

2 回答 2

8
于 2012-11-24T17:58:49.410 回答
3

unutbu's method should be pretty general. If what you're asking for is why it doesn't work after the first iteration, the answer is because of rounding. When you use np.nextafter, you're working at the limit of precision, so any arithmetic operation after that can't be trusted implicitly. In your case, it's probably the + 16 that's the problem. 16 is a couple exponent bits up from 2, so you're going to lose that increment to finite precision. In this case, it takes one extra increment to get that sum to round up instead of down.

于 2012-11-26T17:49:59.313 回答