Beruflich Dokumente
Kultur Dokumente
Lecture 6
Real-valued data in
embedded software
Monday Feb 6, 2012
Philipp Rmmer
Uppsala University
Philipp.Ruemmer@it.uu.se
1/40
Lecture outline
Floating-point arithmetic
Fixed-point arithmetic
Interval arithmetic
2/40
Real values
Signal processing
(Non)linear optimisation
...
3/40
Algebraic numbers
Rational numbers
Arbitrary-precision decimal/binary
numbers
Floating-point numbers
Fixed-point numbers
Arbitrary-precision integers
Bounded integers
5/40
Machine arithmetic
in a nutshell
(applies both to floating-point and fixed-point arithmetic)
7/40
Idealised arithmetic
Idealised operations:
Machine arithmetic
to
9/40
Operation
on
to
Operation
on
10/40
Floating-point arithmetic
12/40
Overview
Significand
(or mantissa)
Infinities
Exponent
Not a number
14/40
Float parameters
Size of significand:
Size of exponent:
Defined range:
bit
bit
15/40
Binary encoding
Exponent size E
Exponent range
binary16
11 bit
5 bit
-24 .. +5
binary32
24 bit
8 bit
-149 .. +104
binary64
53 bit
11 bit
-1074 .. +971
65 bit
15 bit
-16446 .. +16319
binary128
113 bit
15 bit
-16494 .. +16271
16/40
Rounding operations
roundNearestTiesToEven
roundNearestTiesToAway
roundTowardPositive
roundTowardNegative
roundTowardZero
Rounding
up
Rounding
down
17/40
Examples
18/40
Problems with
floating-point
arithmetic
19/40
Problem 1: performance
Problem 2:
mathematical properties
No associativity:
Density/precision varies
often strange for physical data
Standard transformations of
programs/expressions might affect
result
Can exhibit extremely unintuitive
behaviour
21/40
large
close to 0
Pre-sorting to
make
numerically
stable
22/40
Problem 4:
rounding propagation
Bad idea!
inti=0;
floatt=0.0;
floatdeltaT=;
while(){
//
t=deltaT*(float)i;
}
same result?
23/40
Problem 5:
sub-normal numbers
Normal numbers:
Sub-normal numbers have
exponent
and possibly
less precision!
Computation with numbers close to 0
can have strange effects
24/40
Problem 6:
inconsistent semantics
Problem 6:
inconsistent semantics (2)
26/40
Further reading
Pitfalls of floats:
http://arxiv.org/abs/cs/0701192
27/40
Fixed-point arithmetic
28/40
Overview
Domain of
Fixed-point Arithmetic
Significand
(or mantissa)
Fixed
exponent
E.g, for
30/40
Rounding
Implementation
Normally:
Significand
is stored as
integer variable
(32bit, 64bit, signed/unsigned)
Exponent
is fixed upfront
Operations:
Integer operations + shifting
On ARM CORTEX:
partly available as
native instructions
32/40
Operations:
addition, subtraction
No rounding
33/40
Operations: multiplication
34/40
E.g.:
Rounding!
35/40
Intermediate result 12
cannot be stored in 3bit
36/40
Operations: division
Further operations:
pow, exp, sqrt, sin, ...
38/40
Further reading
39/40
In practice ...
40/40