Anda di halaman 1dari 2

www.computing.me.

uk

The Representation of Real Numbers on a Computer
Most computation is carried out using real or floating point numbers. We regularly use large
numbers (for example the speed of light 2.997924591 x 10
8
metres per second
1
) and small
numbers (for example the charge on an electron is -1.610
-19
coulombs
2
). Computers work on
pulses between electrical components and its state is taken to be off or on. Hence numbers on a
computer are represented using the binary system
3
.
The floating point representation of numbers in using the binary system is similar to standard
index form
4
. For example with 2.997924591 x 10
8
the 2.997924591 is the mantissa and the 8
is the exponent and with -1.610
-19
the -1.6 is the mantissa and the -19 is the exponent. A
floating point number on a computer has the form


where m is the mantissa and e is the exponent. Each digit of m and e are stored in binary. A
floating point number is stored on a computer in a number of bytes and each byte stores eight
bits. For example typical modern computer programming languages such as c or Java store a
floating point number in either 4 bytes (called a float) or 8 bytes (called a double)
5
.
The following diagram illustrates how a float is stored in 4 bytes or 32 buts.



sign (1 bit) exponent (8 bit) absolute value of the mantissa
The sign of the mantissa is either + or - and hence this can be stored in one bit. The exponent
is stored in eight bits and the modulus of the mantissa is stored in 23 bits.
Let us consider an example of converting a real number in decimal format
6
and convert it to a 4
byte float in the format above. Starting with a number like 13.875, the first step is to change it to
binary. Using the spreadsheet
7
, we find that 13.87510 = 1101.1112. The convention is to write
this in the form 1.101111 2
3
, so that the 23 bit mantissa is 1.10111100000000000000. The
exponent 3 is stored as 127+3=130 in base 10, so the eight bit exponent is 10000010 (Note
that eight bits can represent 0-255 and the exponent can be negative so the mid-point of 127 is
aligned to zero). The sign bit is 0 to represent that the number is positive.
In summary, 13.875 is represented as
0 1 0 0 0 0 0 1 0 1 1 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
.


1
Electromagnetic Radiation
2
The Discovery of the Nuclear Atom
3
Binary Representation of Numbers
4
Standard Index Form
5
Space and Time
6
Decimal Representation of Numbers
7
Change of Base Excel Spreadsheet
www.computing.me.uk

The smallest number that is greater than 13.875 that can also be represented by this method is
1.1011110000000000000001 2
3
= 13.8750019 The largest number that is less than 13.875
that can also be represented by this method is 1.1011101111111111111110 2
3
=
13.8749981 . Let us illustrate these numbers on the real number line in the following diagram.




13.8749981 13.875 13.8750019

Hence the number 13.875 (like most real numbers) cannot be stored exactly as a float (or in any
other precision. It can only best be stored by as either 13.879981. or 13.8750019, the two
closest numbers that can be represented by the computer as a float . The difference between the
actual number and the value of its representation on a computer is called round-off error.
The maximum value that can be stored in float format is
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

or 1.1111111111111111111122
127
2
128
3.410
38
.
The minimum possible value that can be stored in float format is
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

or 0.000000000000000000000122
-127
2
-149
1.410
-45
, but the actual minimum value is
based on the implementation.

Anda mungkin juga menyukai