06.09.2021 Views

First Semester in Numerical Analysis with Julia, 2020a

First Semester in Numerical Analysis with Julia, 2020a

First Semester in Numerical Analysis with Julia, 2020a

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 1. INTRODUCTION 32<br />

Notice the first sign bit is 0 s<strong>in</strong>ce the number is positive. The next 11 bits (<strong>in</strong> blue) represent<br />

the exponent e = 1026, and the next group of red bits are the mantissa, filled <strong>with</strong> 0’s after<br />

the last digit of the mantissa. In <strong>Julia</strong>, we can get this bit by bit representation by typ<strong>in</strong>g<br />

bitstr<strong>in</strong>g(10.375):<br />

In [1]: bitstr<strong>in</strong>g(10.375)<br />

Out[1]: "0100000000100100110000000000000000000000000000000000000000000000"<br />

Special cases: zero, <strong>in</strong>f<strong>in</strong>ity, NAN<br />

In the float<strong>in</strong>g-po<strong>in</strong>t arithmetic there are two zeros: +0.0 and −0.0, and they have special<br />

representations. In the representation of zero, all exponent and mantissa bits are set to 0.<br />

The sign bit is 0 for +0.0, and 1, for −0.0:<br />

0.0 → 0 0 all zeros 0 0 all zeros 0<br />

−0.0 → 1 0 all zeros 0 0 all zeros 0<br />

When the exponent bits are set to zero, we have e =0and thus e − 1023 = −1023. This<br />

arrangement, all exponents bits set to zero, is reserved for ±0.0 and subnormal numbers.<br />

Subnormal numbers are an exception to our normalized float<strong>in</strong>g-po<strong>in</strong>t representation, an<br />

exception that is useful <strong>in</strong> various ways. For details see Goldberg [9].<br />

Here is how plus and m<strong>in</strong>us <strong>in</strong>f<strong>in</strong>ity is represented <strong>in</strong> the computer:<br />

∞−→ 0 1 all ones 1 0 all zeros 0<br />

−∞−→ 1 1 all ones 1 0 all zeros 0<br />

When the exponent bits are set to one, we have e = 2047 and thus e − 1023 = 1024. This<br />

arrangement is reserved for ±∞ as well as other special values such as NaN (not-a-number).<br />

In conclusion, even though −1023 ≤ e − 1023 ≤ 1024 <strong>in</strong> (1.2), when it comes to represent<strong>in</strong>g<br />

non-zero real numbers, we only have access to exponents <strong>in</strong> the follow<strong>in</strong>g range:<br />

−1022 ≤ e − 1023 ≤ 1023.<br />

Therefore, the smallest positive real number that can be represented <strong>in</strong> a computer is<br />

x =(−1) 0 (1.00 ...0) 2 × 2 −1022 =2 −1022 ≈ 0.2 × 10 −307

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!