Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Floating Point 101

kida
February 06, 2013

Floating Point 101

A very very basic introduction to FP.
With some inaccuracies.

kida

February 06, 2013
Tweet

More Decks by kida

Other Decks in Programming

Transcript

  1. A floating point represents ± (D 1 + D 2

    * B-1 + D 3 * B-2 + … + D n * B(n-1)) * Be
  2. + 10 x 20 1 1.25 1.5 It's also a

    matter of precision
  3. + 11 x 20 1 1.25 1.5 1.75 It's also

    a matter of precision
  4. + 00 x 21 1 1.25 1.5 1.75 2.0 Not

    just a matter of precision or basis...
  5. + 01 x 21 1 1.25 1.5 1.75 2.0 2.5

    Not just a matter of precision or basis...
  6. + 10 x 21 1 1.25 1.5 1.75 2.0 2.5

    3.0 Not just a matter of precision or basis...
  7. Like death and taxes rounding errors are a fact of

    life. http://wiki.octave.org/FAQ
  8. Okay, what about increasing the number of digits use decimal

    representations estimating errors think before you type
  9. More digits, please! double (52 significant bits) long double (112

    significant bits) arbitrary precision * * language support needed
  10. Use float to represent time float time; while (true) time

    += 0.20; This is BAD. And you should feel BAD.
  11. Compare float numbers (a == b) fabs(a -b) <= FLT_EPSILON

    fabs(a - b) <= max(fabs(a),fabs(b)) * pc
  12. 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/)