X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Ftukey-hinges.c;h=b59b878ba64991c2bea385553e24c8e058ab8c2e;hb=946be4d71e8f4e033dbf3a7bccbea0b7cb94a8b3;hp=95a79c1d30026da280cbc6fa2542518c0ff4ad1f;hpb=b5c82cc9aabe7e641011130240ae1b2e84348e23;p=pspp diff --git a/src/math/tukey-hinges.c b/src/math/tukey-hinges.c index 95a79c1d30..b59b878ba6 100644 --- a/src/math/tukey-hinges.c +++ b/src/math/tukey-hinges.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008, 2009, 2011 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 @@ -15,13 +15,17 @@ along with this program. If not, see . */ #include -#include "tukey-hinges.h" -#include -#include -#include +#include "math/tukey-hinges.h" + #include +#include "libpspp/assertion.h" +#include "libpspp/cast.h" +#include "math/order-stats.h" + +#include "gl/xalloc.h" + void tukey_hinges_calculate (const struct tukey_hinges *th, double hinge[3]) { @@ -37,7 +41,7 @@ tukey_hinges_calculate (const struct tukey_hinges *th, double hinge[3]) if (a_star[i] < 1) { - if (os->k[i].c_p1 >= 1 ) + if (os->k[i].c_p1 >= 1) { hinge[i] = (1 - a_star[i]) * os->k[i].y + a_star[i] * os->k[i].y_p1; @@ -59,26 +63,24 @@ tukey_hinges_calculate (const struct tukey_hinges *th, double hinge[3]) static void destroy (struct statistic *s) { - struct order_stats *os = (struct order_stats *) s; - - free (os->k); - free (s); + struct tukey_hinges *th = UP_CAST (s, struct tukey_hinges, parent.parent); + free (th); }; -struct statistic * +struct tukey_hinges * tukey_hinges_create (double W, double c_min) { double d; - struct tukey_hinges *th = xzalloc (sizeof (*th)); - struct order_stats *os = (struct order_stats *) th; - struct statistic *stat = (struct statistic *) th; + struct tukey_hinges *th = XZALLOC (struct tukey_hinges); + struct order_stats *os = &th->parent; + struct statistic *stat = &os->parent; assert (c_min >= 0); os->n_k = 3; - os->k = xcalloc (sizeof (*os->k), 3); + os->k = th->k; - if ( c_min >= 1.0) + if (c_min >= 1.0) { d = floor ((W + 3) / 2.0) / 2.0; @@ -97,5 +99,5 @@ tukey_hinges_create (double W, double c_min) stat->destroy = destroy; - return stat; + return th; }