X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Fpercentiles.c;fp=src%2Fmath%2Fpercentiles.c;h=a9b2913b5c0a47e1f91502abfdde5435b4be7c72;hb=b9f712f8911170fcc049c6d7d83b6887185de4dd;hp=79514eb2504f95d9fd3bfad37c3854aa8fe8c510;hpb=2a76184b55a8c229adc0b31d3436d29076de0ef8;p=pspp diff --git a/src/math/percentiles.c b/src/math/percentiles.c index 79514eb250..a9b2913b5c 100644 --- a/src/math/percentiles.c +++ b/src/math/percentiles.c @@ -143,36 +143,32 @@ destroy (struct statistic *stat) free (ptl); } - /* Create the Pth percentile. W is the total sum of weights in the data set. */ struct percentile * percentile_create (double p, double W) { - struct percentile *ptl = XZALLOC (struct percentile); - struct order_stats *os = &ptl->parent; - struct statistic *stat = &os->parent; - assert (p >= 0); assert (p <= 1.0); - ptl->ptile = p; - ptl->w = W; - - os->n_k = 2; - os->k = ptl->k; - os->k[0].tc = W * p; - os->k[1].tc = (W + 1.0) * p; - - ptl->g1 = ptl->g1_star = SYSMIS; - ptl->g2 = ptl->g2_star = SYSMIS; - - os->k[1].y_p1 = os->k[1].y = SYSMIS; - os->k[0].y_p1 = os->k[0].y = SYSMIS; - - stat->destroy = destroy; - + struct percentile *ptl = xmalloc (sizeof *ptl); + *ptl = (struct percentile) { + .parent = { + .parent = { + .destroy = destroy + }, + .k = ptl->k, + .n_k = 2, + }, + .ptile = p, + .w = W, + .g1 = SYSMIS, + .g1_star = SYSMIS, + .g2 = SYSMIS, + .g2_star = SYSMIS, + .k[0] = { .tc = W * p, .y = SYSMIS, .y_p1 = SYSMIS }, + .k[1] = { .tc = (W + 1.0) * p, .y = SYSMIS, .y_p1 = SYSMIS }, + }; return ptl; } -