Courses / Mathematics I
Scientific Programming

Floating-Point Numbers

Mathematics I 212 words Free to read

Representing the Real World

Scientific computing relies on floating-point numbers to approximate real numbers within finite memory. Stored via the IEEE 754 standard, each value uses a sign, a mantissa for significant digits, and an exponent for scale.

Because storage is finite, most real numbers fall between representable values and are rounded to the nearest tick, causing round-off error. Double precision grants roughly 15–16 significant digits, meaning anything beyond that is noise.

Arithmetic can also trigger infinity from overflow or division by zero, and NaN ("not a number") from invalid operations like 0/00/0, both of which propagate through code.

The Rules of Floating-Point

Numerical computing requires managing fixed precision and gaps instead of expecting exact math. Common issues include:

ProblemCause & ConsequenceSolution
Exact Equality0.1 + 0.2 != 0.3 due to rounding bits.Compare using tolerance: ab<ϵ|a - b| < \epsilon.
Limited PrecisionOnly 15–16 significant digits survive.Track accumulated error limits.
Special ValuesInfinity and NaN propagate through math.Check inputs and handle edge cases.

Common Pitfall: Testing floats with ==. Always use a tolerance (ϵ\epsilon) to avoid failing due to tiny rounding differences.

Floating-Point Numbers

Practise this lesson

The explanation above is free to read. The graded practice for this lesson lives in the Tryals app.

11practice questions
2interactive scenes

Scientific Programming