7 double *
dmax(
double *x,
int n)
10 double *xcopy, sqrt2, sqrtn, mean = 0.0, sdx = 0.0, fx;
11 double dp, dp_max, dm, dm_max;
14 if ((xcopy = (
double *)
malloc(n *
sizeof(
double))) ==
NULL) {
15 fprintf(stderr,
"Memory error in dmax\n");
19 sqrt2 = sqrt((
double)2.0);
20 sqrtn = sqrt((
double)n);
22 for (i = 0; i <
n; ++i) {
27 sdx = sqrt((n * sdx - mean * mean) / (n * (n - 1.0)));
30 qsort(xcopy, n,
sizeof(
double),
dcmp);
32 for (i = 0; i <
n; ++i) {
33 xcopy[i] = (xcopy[i] - mean) / sdx;
34 fx = 0.5 +
normp(xcopy[i] / sqrt2) / 2.0;
41 dp = (double)(i + 1) / (double)n - fx;
42 dm = fx - i / (double)n;
43 if (i == 0 || dp > dp_max)
46 if (i == 0 || dm > dm_max)
int dcmp(const void *i, const void *j)