Modular C
C◼complex◼ldouble◼avgvar: symbols inserted from C◼snippet◼avg.
+ Collaboration diagram for C◼complex◼ldouble◼avgvar: symbols inserted from C◼snippet◼avg.:
C◼complex◼ldouble C◼complex◼ldouble◼avgv (__size n, C◼complex◼ldouble volatile arr[n])
 Compute the average of array arr. More...
 
C◼complex◼ldouble C◼complex◼ldouble◼var3v (__size n, C◼complex◼ldouble volatile arr[n], double est)
 compute the variance of vector arr, by using the estimate of the mean est. More...
 
C◼complex◼ldouble C◼complex◼ldouble◼varv (__size n, C◼complex◼ldouble volatile arr[n])
 Compute the variance of the values in array arr. More...
 
#define C◼complex◼ldouble◼avg(...)   C◼complex◼ldouble◼avgv(sizeof((C◼complex◼ldouble[]){ __VA_ARGS__ })/sizeof(C◼complex◼ldouble), (C◼complex◼ldouble[]){ __VA_ARGS__ })
 Compute the average of arguments. More...
 
#define C◼complex◼ldouble◼var(...)   C◼complex◼ldouble◼varv(sizeof((C◼complex◼ldouble[]){ __VA_ARGS__ })/sizeof(C◼complex◼ldouble), (C◼complex◼ldouble[]){ __VA_ARGS__ })
 Compute the variance of the arguments. More...
 

Detailed Description

See also
C◼snippet◼avg snippet: identifiers inserted directly to an importer for details
This import uses the following slot(s)
slotreplacement
C◼snippet◼avg◼rettypeC◼complex◼ldouble

Macro Definition Documentation

§ C◼complex◼ldouble◼avg

#define C◼complex◼ldouble◼avg (   ...)    C◼complex◼ldouble◼avgv(sizeof((C◼complex◼ldouble[]){ __VA_ARGS__ })/sizeof(C◼complex◼ldouble), (C◼complex◼ldouble[]){ __VA_ARGS__ })

Compute the average of arguments.

Definition at line 501 of file C-complex-ldouble.c.

§ C◼complex◼ldouble◼var

#define C◼complex◼ldouble◼var (   ...)    C◼complex◼ldouble◼varv(sizeof((C◼complex◼ldouble[]){ __VA_ARGS__ })/sizeof(C◼complex◼ldouble), (C◼complex◼ldouble[]){ __VA_ARGS__ })

Compute the variance of the arguments.

Definition at line 547 of file C-complex-ldouble.c.

Function Documentation

§ C◼complex◼ldouble◼avgv()

C◼complex◼ldouble C◼complex◼ldouble◼avgv ( __size  n,
C◼complex◼ldouble volatile  arr[n] 
)
inline

Compute the average of array arr.

Returns
defaults to double if not overwritten by the importer.

Definition at line 492 of file C-complex-ldouble.c.

492  {
493 #line 23 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
495  return ret/n;
496 }
C◼complex◼ldouble C◼complex◼ldouble◼sumv(__size n, C◼complex◼ldouble volatile arr[n])
Perform cumulative operation on array arr of length n.
long double _Complex C◼complex◼ldouble

§ C◼complex◼ldouble◼var3v()

C◼complex◼ldouble C◼complex◼ldouble◼var3v ( __size  n,
C◼complex◼ldouble volatile  arr[n],
double  est 
)
inline

compute the variance of vector arr, by using the estimate of the mean est.

If est is the exact mean, the centered mean m1 would be zero if there wouldn't be any rounding errors, and theoretically we could avoid this part of the computation. But in case that there are in fact rounding errors, this here is the good strategy to compensate for them. This is in particular relevant if n is large and rounding errors may accumulate to a substantial value.

Returns
defaults to double if not overwritten by the importer.

Definition at line 517 of file C-complex-ldouble.c.

517  {
518 #line 47 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
519  C◼complex◼ldouble m1 = 0;
520  C◼complex◼ldouble m2 = 0;
521  for (__size i = 0; i < n; ++i) {
522 #line 50 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
523  C◼complex◼ldouble val = (arr[i] - est);
524  m1 += val;
525  m2 += val*val;
526  }
527  return (m2 - m1*m1/n)/(n-1);
528 }
long double _Complex C◼complex◼ldouble

§ C◼complex◼ldouble◼varv()

C◼complex◼ldouble C◼complex◼ldouble◼varv ( __size  n,
C◼complex◼ldouble volatile  arr[n] 
)
inline

Compute the variance of the values in array arr.

This could be computed faster, by first computing the average and then only the squares of the deviations of that. Using var3v() results in so-called compensated variance calculation that is numerically more stable.

Definition at line 539 of file C-complex-ldouble.c.

539  {
540 #line 67 "/home/gustedt/build/cmod/C/C-snippet-avg.X"
542 }
C◼complex◼ldouble C◼complex◼ldouble◼var3v(__size n, C◼complex◼ldouble volatile arr[n], double est)
compute the variance of vector arr, by using the estimate of the mean est.
C◼complex◼ldouble C◼complex◼ldouble◼avgv(__size n, C◼complex◼ldouble volatile arr[n])
Compute the average of array arr.