floating-point arithmetic
Scientists write very big and very small numbers in scientific notation, like 6.022 * 10^23 or 1.6 * 10^(-19): a handful of significant digits times a power of ten that slides the decimal point wherever it needs to go. Floating-point arithmetic is the computer's version of this idea, done in base 2: it keeps a fixed number of significant bits and lets the binary point float via a stored exponent, so a single 64-bit word can describe both the mass of a galaxy and the size of an atom.
Each elementary operation — add, subtract, multiply, divide, square root — takes its true real-number result and then rounds it to the nearest representable floating-point number. The standard way to model this is fl(x op y) = (x op y)(1 + delta) with |delta| <= u, where u is the unit roundoff: every single operation is correct to within a tiny relative wobble. The hardware genuinely computes the exact result first (conceptually) and rounds once, so one operation is as accurate as the format allows.
The crucial honesty: floating-point arithmetic is NOT real arithmetic. The representable numbers are finite and unevenly spaced, so familiar laws can fail — addition is not associative, (a + b) + c can differ from a + (b + c), and 0.1 + 0.2 is not exactly 0.3. Each operation is nearly exact, but errors ACCUMULATE across millions of operations, and a careless formula can lose almost all its digits in a single subtraction. The whole craft of numerical computing is arranging calculations so these small, well-understood errors stay small.
In double precision, 0.1 + 0.2 evaluates to 0.30000000000000004, not 0.3, because neither 0.1 nor 0.2 is stored exactly and the rounded sum lands one step above 0.3's nearest representable value. So the test (0.1 + 0.2 == 0.3) returns false — a classic beginner shock that is entirely correct behaviour.
Each operation rounds; small representation errors then propagate.
A single floating-point operation is nearly perfect (relative error <= u); the danger is the SEQUENCE. Never test two computed floats for exact equality — compare with a tolerance scaled to the values' magnitude.