GRASS 8 Programmer's Manual  8.5.0dev(2025)-c070206eb1
var.c
Go to the documentation of this file.
1 #include <math.h>
2 #include <grass/imagery.h>
3 /* sum: sum of x
4  * sum2: sum of x squared
5  * n: number of points
6  */
7 double I_variance(double sum, double sum2, int n)
8 {
9  if (n < 2)
10  return ((double)0.0);
11  else
12  return ((sum2 - sum * sum / n) / (n - 1));
13 }
14 
15 double I_stddev(double sum, double sum2, int n)
16 {
17  if (n < 2)
18  return ((double)-99.0);
19  else
20  return sqrt(I_variance(sum, sum2, n));
21 }
double I_stddev(double sum, double sum2, int n)
Definition: var.c:15
double I_variance(double sum, double sum2, int n)
Definition: var.c:7