Skip to main content
Engineering LibreTexts

15.6: Chapter Summary

  • Page ID
    43755
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Floats are approximation of a real number by being able to support a wide range of decimal values. This chapters has reviewed the following points

    • Never use = to compare floats (e.g., \( (0.1 + 0.2) = 0.3 \) returns false)
    • Use closeTo: instead (e.g., (0.1 + 0.2) closeTo: 0.3 returns true)
    • A float number is represented in base as \( \mathit{sign} \times \mathit{mantissa} \times 2^{\mathit{exponent}} \) (e.g., \( 1.2345 = 12345 \times 10^{-4} \))
    • truncateTo: and roundTo: do not always work when truncating or rounding up float (e.g., 2.8 roundTo: 0.01 returns 2.800...003)

    There are much more things to know about floats, and if you are advanced enough, it would be a good idea to check this link from the Wikipedia page "What Every Computer Scientist Should Know About Floating-Point Arithmetic" (http://www.validlab.com/goldberg/paper.pdf).


    This page titled 15.6: Chapter Summary is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by Alexandre Bergel, Damien Cassou, Stéphane Ducasse, Jannik Laval (Square Bracket Associates) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.