X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Fpercentiles.c;h=c76bb492ba767a90ffa2c03c8d35bf8a7d532ab6;hb=d9f325b49bfe8d2eb871d35e07be427c9ed29b87;hp=53d704d623036981d99ae49d49677498542e010a;hpb=bb611ecc6f1c33a0a7c691785927c545d18696f6;p=pspp-builds.git diff --git a/src/math/percentiles.c b/src/math/percentiles.c index 53d704d6..c76bb492 100644 --- a/src/math/percentiles.c +++ b/src/math/percentiles.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,6 +24,7 @@ #define N_(msgid) msgid #include +#include #include #include #include @@ -44,9 +45,11 @@ const char *const ptile_alg_desc[] = { double percentile_calculate (const struct percentile *ptl, enum pc_alg alg) { - struct percentile *mutable = (struct percentile *) ptl; + struct percentile *mutable = CONST_CAST (struct percentile *, ptl); const struct order_stats *os = &ptl->parent; + assert (os->cc == ptl->w); + if ( ptl->g1 == SYSMIS) mutable->g1 = (os->k[0].tc - os->k[0].cc) / os->k[0].c_p1; @@ -152,23 +155,25 @@ percentile_calculate (const struct percentile *ptl, enum pc_alg alg) static void destroy (struct statistic *stat) { - struct order_stats *os = (struct order_stats *) stat; + struct percentile *ptl = UP_CAST (stat, struct percentile, parent.parent); + struct order_stats *os = &ptl->parent; free (os->k); - free (os); + free (ptl); } -struct order_stats * +struct percentile * percentile_create (double p, double W) { struct percentile *ptl = xzalloc (sizeof (*ptl)); - struct order_stats *os = (struct order_stats *) ptl; - struct statistic *stat = (struct statistic *) ptl; + 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 = xcalloc (sizeof (*os->k), 2); @@ -183,18 +188,6 @@ percentile_create (double p, double W) stat->destroy = destroy; - return os; + return ptl; } -#if 0 -void -percentile_dump (const struct percentile *ptl) -{ - printf ("Percentile %g:\n\tk1: ", ptl->ptile); - - dump_os_k1 ((const struct os *)ptl); - printf ("\tk2: "); - dump_os_k2 ((const struct os *)ptl); - printf ("\n"); -} -#endif