SD & D Real Numbers

Post on 21-Jan-2018

752 views 0 download

Transcript of SD & D Real Numbers

What are Real Numbers?Real Numbers include:

Whole Numbers (like 1,2,3,4, etc)

Rational Numbers (like 3/4, 0.125, 0.333..., 1.1, etc )

Irrational Numbers (like π, √3, etc )

Real Numbers can also be positive, negative or zero

What are Real Numbers?Real Numbers include:

Whole Numbers (like 1,2,3,4, etc)

Rational Numbers (like 3/4, 0.125, 0.333..., 1.1, etc )

Irrational Numbers (like π, √3, etc )

Real Numbers can also be positive, negative or zero

15 3148

-272/7

99/10014.75

0.000123100.159 π

√3340.1155

22.9

In Computing, real numbers are also known as f loating point numbers

Binary Real NumbersWhat do real numbers look like in binary?

In binary, the numbers after the decimal point have the following place values:

1/2 1/4 1/8 1/16 1/32 1/64 1/128

Binary Real NumbersWhat do real numbers look like in binary?

In binary, the numbers after the decimal point have the following place values:

1/2 1/4 1/8 1/16 1/32 1/64 1/128

So, 8.5 could be represented as:

1000 before the decimal point (8)and 1 after the decimal point (0.5)

8.5 = 1000.1

Binary Real NumbersWhat do real numbers look like in binary?

In binary, the numbers after the decimal point have the following place values:

1/2 1/4 1/8 1/16 1/32 1/64 1/128

So, 14.625 could be represented as:

1110 before the decimal point (14)and 101 after the decimal point (0.625)

14.625 = 1110.101

Standard FormStandard form is a scientific notation of representing numbers as a base number and an exponent.

Standard FormStandard form is a scientific notation of representing numbers as a base number and an exponent.

Using this notation:

The decimal number 8674.26 can be represented as

8.67426 x 103

mantissa = 8.67426base = 10 exponent = 3

Standard FormStandard form is a scientific notation of representing numbers as a base number and an exponent.

Using this notation:

The decimal number 753.34 can be represented as

7.5334 x 102

mantissa = 7.5334base = 10 exponent = 2

Standard FormStandard form is a scientific notation of representing numbers as a base number and an exponent.

Using this notation:

The decimal number 0.000634 can be represented as

6.34 x 10-3

mantissa = 6.34base = 10 exponent = -3

Standard FormStandard form is a scientific notation of representing numbers as a base number and an exponent.

Any number can be represented in any number base in the form m x be

Standard FormStandard form is a scientific notation of representing numbers as a base number and an exponent.

Any number can be represented in any number base in the form m x be

This also applies to binary numbers, which have a base of 2.

Binary numbers can be represented as m x 2e

Floating Point NotationIn floating point notation, the real number is stored as 2 separate bits of data

A storage location called the mantissa holds the complete number without the point.

Floating Point NotationIn floating point notation, the real number is stored as 2 separate bits of data

A storage location called the mantissa holds the complete number without the point.

A storage location called the exponent holds the number of places that the point must be moved in the original number to place it at the left hand side.

Floating Point NotationWhat is the exponent of 10110.110?

The exponent is 5, because the decimal point has to be moved 5 places to get it to the left hand side.

The exponent would be represented as 0101 in binary

Floating Point NotationHow would 10110.110 be stored using 8 bits for the mantissa and 4 bits for the exponent?

We have already calculated that the exponent is 5 or 0101.

10110.110 = 10110110 x 25 = 10110110 x 20101

It is not necessary to store the ‘x’ sign or the base because it is always 2.

Mantissa Exponent

Floating Point NotationHow would 24.5 be stored using 8 bits for the mantissa and 4 bits for the exponent?

Remember, in binary, the numbers after the decimal point have the following place values:

1/2 1/4 1/8 1/16 1/32 1/64 1/128

24 has the binary value 110000.5 (or 1/2) has the binary value .1

24.5 = 0011000.1

Floating Point NotationHow would 0011000.1 be stored using 8 bits for the mantissa and 4 bits for the exponent?

Floating Point NotationHow would 0011000.1 be stored using 8 bits for the mantissa and 4 bits for the exponent?

The exponent is 7 because decimal point has to move 7 places to the left

0011000.1 = 00110001 x 27 = 00110001 x 20111

Mantissa Exponent

AccuracyStore 110.0011001 in floating point representation, using 8 bits for the mantissa and 4 bits for the exponent.

Mantissa Exponent

The mantissa only holds 8 bits and so cannot store the last two bits

These two bits cannot be stored in the system, and so they are forgotten.

The number stored in the system is 110.00110 which is less accurate that its initial value.

AccuracyIf the size of the mantissa is increased then the accuracy of the number held is increased.

Mantissa (10 bits) Exponent

RangeIf increasing the size of the mantissa increases the accuracy of the number held, what will be the effect of increasing the size of the exponent?

Using two bits for the exponent, the exponent can have the value 0-3

Mantissa Exponent (2 bits)

This means the number stored can be in the range

.00000000 (0) to111.11111 (7.96875)

RangeIncreasing the exponent to three bits, it can now store the values 0-7

Mantissa Exponent (3 bits)

This means the number stored can be in the range

.00000000 (0) to1111111.1 (127.5)

If the size of the exponent is increased then the range of the numbers which can be stored is increased.

Floating Point NotationAdvantage:We can store very large and very small numbers using a small number of bits

Disadvantage:The accuracy of the number being represented is lost because numbers get rounded

CreditsHigher Computing – Data Representation – Representation of Real Numbers

Produced by P. Greene and adapted by R. G. Simpson for the City of Edinburgh Council 2004

Adapted by M. Cunningham 2010

All images licenced under Creative Commons 3.0• Happy Pi Day by Mykl Roventine