Single precision up to ~10+38.
FP REPRESENTS A WIDE RANGE
Slide 51
Slide 51 text
HE APPROVES FP
Slide 52
Slide 52 text
Anyway, errors still there.
Slide 53
Slide 53 text
Okay, what about
increasing the number of digits
use decimal representations
estimating errors
think before you type
Slide 54
Slide 54 text
More digits, please!
double (52 significant bits)
long double (112 significant bits)
arbitrary precision *
* language support needed
Slide 55
Slide 55 text
Use decimal representations!
decimal (C# only)
BigDecimal (Java only)
std::decimal (C++, coming soon)*
* after IEEE-754 2008
Slide 56
Slide 56 text
Estimate the error of your algo
rel_err = fabs(f – fp) / f
Slide 57
Slide 57 text
Use float to represent time
float time;
while (true) time += 0.20;
Slide 58
Slide 58 text
Use float to represent time
float time;
while (true) time += 0.20;
This is BAD.
And you should feel BAD.
Slide 59
Slide 59 text
Compare float numbers
(a == b)
Slide 60
Slide 60 text
Compare float numbers
(a == b)
fabs(a -b) <= FLT_EPSILON
Slide 61
Slide 61 text
Compare float numbers
(a == b)
fabs(a -b) <= FLT_EPSILON
fabs(a - b) <=
max(fabs(a),fabs(b)) * pc
Slide 62
Slide 62 text
There is no silver bullet.
Slide 63
Slide 63 text
Use libraries (when available).
Slide 64
Slide 64 text
Vector addition (naive)
float t[SIZE];
float result;
for (i = 0; i < SIZE; ++i)
result += t[i];
Slide 65
Slide 65 text
RESCUE
GNU GSL
TO THE
Slide 66
Slide 66 text
No content
Slide 67
Slide 67 text
that's all folks!
@lorisfichera – https://kid-a.github.com
References and source code available at
https://github.com/kid-a/floating-point-seminar
Credits
Font: Yanone Kaffeesatz
(http://www.yanone.de/typedesign/kaffeesatz/)