> It is surprisingly easy to get unexpected negative values with floating point operations.
This why one should NEVER compute variance as difference of E(x^2) - (E(x))^2. Mathematically with infinite precision it is the same as E((x-E(x))^2) but in floating point arithmetic one can easily get negative variance when subtracting two floating numbers.
This why one should NEVER compute variance as difference of E(x^2) - (E(x))^2. Mathematically with infinite precision it is the same as E((x-E(x))^2) but in floating point arithmetic one can easily get negative variance when subtracting two floating numbers.