Fearful Floats: Problems For Programmers IEEE-754 Floating Point Representation
Fearful Floats: Problems For Programmers IEEE-754 Floating Point Representation
Fractional representation!
The task:
Use 6 bits to represent fractional numbers
using binary representation.
Binary to decimal!
2-1
2-2
2-6
2-5
2-4
2-3
n exponent
bits
6-n-1 mantissa
bits
This is the approach used in scientific notation . Thus, in
decimal, 315.82 could be expressed as 3.1582 x 102.
mantissa =
3.1582
exponent =
2
General structure
Floating point widths are commonly referred to as:
single-precision
32b
double-precision
64b
extended-precision
80b
Sign bit
Exponent
Mantissa
Normalisation!
Normalisation is a convention that leaves the mantissa
in the form:
1.xxxxx
where x represents a binary digit.
Thus,
1101.101
normalises to
1.101101000 x 23
De-normalised numbers!
An exponent field that is filled with zeros
denotes a denormalised number.
This means that the assumption of a leading
1 in the mantissa does not apply
Apart from other things, this enables the value
0.0 to be represented...
11
Infinity!
An exponent field that is filled with ones,
together with a mantissa field that is filled
with zeros denoted infinity.
Note the use of the sign bit allows both
positive and negative infinity to be defined.
12
Design considerations
Range
It is desirable for the representation method to
include as wide a range (maximum - minimum) as
possible
13
Design considerations
Density
It is not possible to represent all numbers. It is desirable to have
as high a density of computer-representable numbers as
possible.
To make the point, consider the numbers able to be represented
by the following fixed-point system:
0
Representable
numbers:
0.1 * 10 = ?
1.0
20! = ?
a really big number
(something around 2.432902008176640e+018)
17
What!does!this!print?!
!float x = 0.1;
printf("%10.1f\n", x);
printf("%10.5f\n", x);
printf("%20.15f\n", x);
printf("%50.45f\n", x);
!!!!!!!!
18
19
Catastrophic!cancella2on!
Two!operands!are!close!to!each!other!
They!cancel!out!because!of!order!of!the!
opera2on,!eg!
bignum!<!bignum!+!smallnum!
Quadra2c!equa2on!discriminant!
20
Catastrophic!cancella2on!
b = 3.34
a = 1.22
c = 2.28
exact (b * b) - 4 * a * c
.0292
(b * b) rounds to 11.2
4ac to 11,1
answer 0.1
21
Benign!cancella2on!
Avoid!the!problems!by!reorganising!the!
expression!
Example:!catastrophic!cancella2on!
(x!*!x)!<!(y!*!y)!has!catastrophic!
Becomes!benign!(more!accurate)!as!
(x!<!y)(x!+!y)!
22
About!errors!
Sources!
The!raw!data!eg!7.3!
Propaga2on!error!eg!7.3!+!8.15!
Representa2onal!errors!(niteness)!
Awareness!
Signicant!gures!
Prin2ng!
calcula2ons!
Measures!
Absolute!error!
Rela2ve!error!
23
24
25
June 4, 1996
Ariane 5 is launched
26
27
Oops! An $(US)8-billion
fireworks display!!
!Computed
29
30
31
32
Summary!
Appreciation of floating point problems:
big disasters may result from small errors
small errors are hard to find
33
end of segment
34
35
1982+
The Vancouver Stock Exchange!
36
37
Sources!
David!Goldberg,!What!Every!Computer!Scien2st!Should!Know!about!Floa2ng<
Point!Arithme2c,!covers!important!aspects!of!oa2ng<point!arithme2c!from!the!
perspec2ve!of!IEEE!754!from!the!IEEE!web!site.!
Kernighan!and!Pike,!Prac2ce!of!Programming.!
Ariane 5 video
http://www.abc.net.au/news/imageLibrary/00/04/18/g00041820000418stocks.jpg
http://www.mpia-hd.mpg.de/SUW/SuW/1996/10-96/S713Abb1.html
STX photo:
http://graffiti.cribx1.u-bordeaux.fr/roussel/anim-e_07f.shtml
http://www.estec.esa.nl/spdwww/cluster/restored/pics/ar5lnch.mpg
http://www.washingtonpost.com/wp-srv/inatl/images/fogofwarpics/analysis/bombing1.jpg
http://www.ima.umn.edu/~arnold/disasters/patriot.html
38
end of segment
39
00000000
127
01111111
255
11111111
40