Scientific notation is used to represent large or small decimal numbers. These have two parts, the $\color{red}\text{significand}$ (mantissa) and the $\color{blue}\text{exponent}$.
The IEEE-754 format is a standard specified by the **IEEE** for representing floating-point binary numbers. The two versions of the format that are most common are **single precision** (32-bits) and **double precision** (64-bits).
The bias is an offset which is always applied to the exponent of a floating point number, $127$ for single precision and $1023$ for double precision.
We use a bias instead of two’s complement as it allows for the numeric ordering to be the same as the lexicographic ordering which allows fast size comparisons of numbers.
The sign bit behaves the same way as in signed-magntiude.
The exponent and significand are not just unsigned.
title: Example 1Take $11000001001011000000000000000000$.We first break it down to individual components: $\color{green}1 \color{blue}1000010\color{red}01011$.- $\color{green}1$ is the $\color{green}\text{sign bit}$ which tells us it is negative.- $\color{blue}1000010$ is the $\color{blue}\text{exponent}$. This value is $130_{10} - 127_{10} (\text{bias}) = 3_{10}$.- $\color{red}01011$ is the $\color{red}\text{significand}$. Significand is $1.01011$ with the implied leading $1$.So, our final value is $- 1.01011 \times 2^3 = - 1010.11_2 \rightarrow - 10.75_{10}$.
title: Example 2Take $-133.25_{10}$.Convert to binary and normalise:$$ \begin{aligned} 133.25 &\rightarrow 1000101.01 \times 2^0 \\ &= 1.000010101 \times 2^7 \\ &= {\color{red}00001010100000000000000_2} \\ \\ 2^7 &\rightarrow 7 + 127 \\ &= 137 \\ &= {\color{blue}10000110_2} \end{aligned}$$Sign is negative so $\color{green}1$.Hence final value is ${\color{green}1}{\color{blue}10000110}{\color{red}00001010100000000000000}$.
Special values
Using normalised form, it is not possible to represent 0, so there is a special value specified which we use for 0.
Range is the difference between the maximum and minimum value re-presentable in a given format. Although it does not mean all values are re-presentable within that range.
The range of double precision numbers is:
−1×10308 to −1×10−308 and 1×10308 to 1×10−308
Precision
Precision refers to how much information a representation gives us of a value.
3.14 gives us 2 digits of precision right of the decimal point.
3.142 gives us 3 digits of precision right of the decimal point.
More precision doesn’t mean more accuracy, 3.14 is a more accurate representation of π than 3.149 even though it is less precise.
Accuracy refers to how close a representation of a value is to the true value.
Relative error is a measure of accuracy of a representation.
Relative error = T∣T−R∣×100, where T is the true value and R is the value that is represented.
For example, we know there is no exact representation of 0.310 in binary:
In 5-bit fixed-point binary, with point between 4-3, the most accurate is 0.01002=0.2510.
The accuracy is 0.3∣0.3−0.25∣×100=16.67%.