SchoolWhool
Quizzes and saved progress, freeSign in freeSign in
Maths · Module 5Module material

Floating point and numerical computing interview questions

10 questions interviewers ask on numbers on a computer, from first principles to the follow-ups. The first 3 model answers are free to read; Pro opens the rest.

  1. Why does 0.1 + 0.2 == 0.3 return False?

    A float64 stores the nearest number with 53 significant binary digits. 0.1, 0.2 and 0.3 have binary expansions that never end, so all three are rounded, and the rounded sum is the float just above the one stored for 0.3: 0.30000000000000004. Compare floats with a tolerance instead.

  2. What is machine epsilon?

    The gap between 1 and the next float: 2⁻⁵² ≈ 2.22 × 10⁻¹⁶ in float64, 1.19 × 10⁻⁷ in float32. Rounding to the nearest float has a relative error of at most half of it. The absolute gap grows with the number: at 10¹⁶ it is 2, so 1e16 + 1 == 1e16.

  3. What is catastrophic cancellation? Give an example.

    Subtracting two nearly equal numbers keeps only the digits where they differ, so the rounding error each carried becomes most of the answer. A forward difference with a tiny step is one case; the one-pass variance formula mean(x²) − mean(x)² is another: on 10⁹ + [4, 7, 13, 16] it returns −128.0 instead of 22.5.

  4. How do you choose the step for a numerical gradient check?
  5. What are overflow and underflow, and how does NumPy report them?
  6. Why do Naive Bayes implementations add log probabilities?
  7. What is log-sum-exp, and why is it stable?
  8. How do you compute a softmax safely?
  9. Why should log loss be computed from the score rather than the probability?
  10. When would you train in float32 instead of float64, and what do you watch for?