Problem with non positive defined covariance matrices

Due to round off errors, the formula used to compute the weighted covariance matrix may lead to matrices with large negative eigenvalues.

The formula is:
C = \sum_i w_i (x_i - \mu)(x_i - \mu)'                         (1)
C = (\sum_i w_i x_i x_i')  - \mu \mu'                           (2)

assuming \sum_i w_i = 1 and \mu = \sum_i w_i x_i

The second formula does not guarantee that C is positive definite.