Presentation is loading. Please wait.

Presentation is loading. Please wait.

Floating point numbers. Computable reals computable numbers may be described briefly as the real numbers whose expressions as a decimal are calculable.

Similar presentations


Presentation on theme: "Floating point numbers. Computable reals computable numbers may be described briefly as the real numbers whose expressions as a decimal are calculable."— Presentation transcript:

1 Floating point numbers

2 Computable reals computable numbers may be described briefly as the real numbers whose expressions as a decimal are calculable by finite means.( A. M. Turing, On Computable Numbers with an Application to the Entschiedungsproblem, Proc. London Mathematical Soc., Ser. 2, Vol 42, pages , )

3 Look first at decimal reals A real number may be approximated by a decimal expansion with a determinate decimal point. As more digits are added to the decimal expansion the precision rises. Any effective calculation is always finite – if it were not then the calculation would go on for ever. There is thus a limit to the precision that the reals can be represented as.

4 Transcendental numbers In principle, transcendental numbers such as Pi or root 2 have no finite representation We are always dealing with approximations to them. We can still treat Pi as a real rather than a rational because there is always an algorithmic step by which we can add another digit to its expansion.

5 First solution Store the numbers in memory just as they are printed as a string of characters Would be stored as 6 bytes as shown below Note that decimal numbers are in the range 30H to 39H as ascii codes E3735 Full stop char Char for 3

6 Implications The number strings can be of variable length. This allows arbitrary precision. This representation is used in systems like Mathematica which requires very high accuracy.

7 Example with Mathematica 5! Out[1]=120 In[2]:=10! Out[2]= In[3]:=50! Out[3]=

8 Decimal byte arithmetic 9+ 8= 17 decimal 39H+38H=71H hexadecimal ascii 57+56=113 decimal ascii Adjust by taking 30H =48 away -> 41H =65 If greater than 9= 39H =57 take away 10= 0AH and carry 1 Thus 41H-0Ah = 65-10=55= 37H so the answer would be 31H,37H = 17

9 Representing variables Variables are represented as pointers to character strings in this system A= A E3735

10 Advantages Arbitrarily precise Needs no special hardware Disadvantages Slow Needs complex memory management

11 Binary Coded Decimal (BCD) or Calculator style floating point Note that can be represented as x 10 2 Store this 2 digits to a byte to fixed precision as follows bits overall Each digit uses 4 bits exponentmantissa

12 Normalise Convert N to format with one digit in front of the decimal point as follows: 1.If N>10 then Whilst N>10 divide by 10 and add 1 to the exponent 2.Else whilst N<1 multiply by 10 and decrement the exponent

13 Add floating point 1.Denormalise smaller number so that exponents equal 2.Perform addition 3.Renormalise Eg = E E E E E03

14 Note loss of accuracy Compare Octave which uses floating point numbers with Mathematica which uses full precision arithmetic Octave floating point gives only 5 figure accuracy Octave fact(5) ans = 120 fact(10) ans = fact(50) ans = e+64 Mathematica 5! Out[1]=120 10! Out[2]= ! Out[3]=

15 Loss of precison continued When there is a big difference between the numbers the addition is lost with floating point Octave ans = D+08 Mathematica In[1]:= Out[1]=

16 IEEE floating point numbers Institution of Electrical and Electronic Engineers

17 Single Precision EF

18 Definition N=-1 s x 1.F x 2 E-128 Example In fixed point binary = = x 2 1 In IEEE format this is s=0 E=129, F=10100… thus in IEEE it is S E F 0| | Delete this bit

19 Example = -3/8 In fixed point binary = =-1 1 x 1.1 x 2 -2 In IEEE format this is s=1 E=126, F=1000 … thus in IEEE it is S E F 1| |

20 Range IEEE * 10 –38 to * IEEE * 10 –308 to * bit 3.37 * 10 –4932 to *

21


Download ppt "Floating point numbers. Computable reals computable numbers may be described briefly as the real numbers whose expressions as a decimal are calculable."

Similar presentations


Ads by Google