Algorithms and Data Structures · Senior · Question 49 of 75

Why does 0.1 + 0.2 !== 0.3 matter for algorithms?

Explanation

Binary floating point can't represent 0.1 exactly, and errors accumulate in long sums or geometry code. Compare with Math.abs(a - b) < epsilon, use integers (cents instead of dollars), or BigInt for exact integer math.

Further reading

Problem with a question

Algorithms and Data Structures · Senior · question 49

Test yourself

Take the Algorithms and Data Structures · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz