Maximus - 1 year ago 80

Javascript Question

I'm trying to understand what minimum number I need to add to get

`Infinity`

`0 0000 000`

The maximum positive number I can store in it is this:

`0 1110 111`

which is when converted to scientific notation:

`1.111 x 2^{7} = 11110000`

Is my understanding correct that the minimum number I should add to get

`Infinity`

`00010000`

`11110000`

+ 00010000

--------

1 00000000

As I understand anything less than

`00010000`

`11110000`

`00010000`

`0 0000 001`

`1`

`1`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

The answer is given in the other answer to the question you link to. The smallest value which will round to infinity is:

*c* = 2^{7} × ( 2 − ½ × 2^{1-4} ) = 1.9375 × 2^{7} = 1.1111_{2} × 2^{7}

So the smallest value that you can add to get infinity is

*c* - *f*_{max} = 1.1111_{2} × 2^{7} - 1.111_{2} × 2^{7} = 0.0001_{2} × 2^{7} = 2^{3}

which, if I understand correctly, would have bit pattern `0 1010 000`

in your proposed format.

UPDATE: so why is it this particular cutoff?

Suppose that there was another binade above this one, then the next floating point number would be

*x* = 1.000_{2} × 2^{8}

Note that *c* is the value that is exactly halfway between *x* and *f*_{max}. In other words, the values which would round up to *x* are instead rounded to infinity, but the values which would round down to *f*_{max} still round to the same value.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**