Unit in The Last Place - Example

Example

If ULP(x) is less than or equal to 1, then x + 1 > x. Otherwise, x + 1 = x. This is demonstrated in the following Haskell code typed at an interactive prompt:

> until (\x -> x == x+1) (+1) 0 :: Float 1.6777216e7 > it-1 1.6777215e7 > it+1 1.6777216e7

Here we start with 0 in 32-bit single-precision and repeatedly add 1 until the operation is idempotent. The result is equal to 224 (in hex, 4b800000) since the significand for a single-precision number in this example contains 24 bits.

Another example, in Python, also typed at an interactive prompt, is:

>>> x = 1.0 >>> p = 0 >>> while x != x + 1: ... x = x * 2 ... p = p + 1 ... >>> x 9007199254740992.0 >>> p 53

In this case, we start with x = 1 and repeatedly double it until x = x + 1. The result is 253, because the double-precision floating-point used a 53-bit significand.

Read more about this topic:  Unit In The Last Place

Famous quotes containing the word example:

    Our intellect is not the most subtle, the most powerful, the most appropriate, instrument for revealing the truth. It is life that, little by little, example by example, permits us to see that what is most important to our heart, or to our mind, is learned not by reasoning but through other agencies. Then it is that the intellect, observing their superiority, abdicates its control to them upon reasoned grounds and agrees to become their collaborator and lackey.
    Marcel Proust (1871–1922)