Question: I need to know if a number compared to a set of numbers is outside of 1 stddev from the mean, etc..

Answer: 
While the sum of squares algorithm works fine most of the time, it can cause big trouble if you are dealing with very large numbers. You basically may end up with a negative variance...

Plus, don't never, ever, ever, compute a^2 as pow(a,2), a \* a is almost certainly faster.

By far the best way of computing a standard deviation is [Welford's method](http://www.johndcook.com/standard_deviation.html). My C is very rusty, but it could look something like:

```
public static double StandardDeviation(List<double> valueList)
{
    double M = 0.0;
    double S = 0.0;
    int k = 1;
    foreach (double value in valueList) 
    {
        double tmpM = M;
        M += (value - tmpM) / k;
        S += (value - tmpM) * (value - M);
        k++;
    }
    return Math.Sqrt(S / (k-2));
}

```

If you have the *whole* population (as opposed to a *sample* population), then use `return Math.Sqrt(S / (k-1));`.

**EDIT:** I've updated the code according to Jason's remarks...

**EDIT:** I've also updated the code according to Alex's remarks...
The accepted answer by Jaime is great, except you need to divide by k-2 in the last line (you need to divide by "number\_of\_elements-1").
Better yet, start k at 0:

```
public static double StandardDeviation(List<double> valueList)
{
    double M = 0.0;
    double S = 0.0;
    int k = 0;
    foreach (double value in valueList) 
    {
        k++;
        double tmpM = M;
        M += (value - tmpM) / k;
        S += (value - tmpM) * (value - M);
    }
    return Math.Sqrt(S / (k-1));
}

```