Update all #include directives to the currently preferred style.
[pspp-builds.git] / src / math / percentiles.c
index bf99de163ffbaafe2af8711685e9a640a0256784..ed7b129576f1f7d6b713f46af75ef77aeab3dbf8 100644 (file)
@@ -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
    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <config.h>
-#include "percentiles.h"
-#include <math/order-stats.h>
 
+#include "math/percentiles.h"
+
+#include "data/casereader.h"
+#include "data/val-type.h"
+#include "data/variable.h"
+#include "libpspp/assertion.h"
+#include "libpspp/cast.h"
+#include "math/order-stats.h"
+
+#include "gl/xalloc.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 #define N_(msgid) msgid
 
-#include <libpspp/assertion.h>
-#include <data/val-type.h>
-#include <gl/xalloc.h>
-#include <data/variable.h>
-#include <data/casereader.h>
-
-
 const char *const ptile_alg_desc[] = {
   "",
   N_("HAverage"),
@@ -44,7 +45,7 @@ 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);
@@ -154,18 +155,19 @@ 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);
@@ -186,6 +188,6 @@ percentile_create (double p, double W)
 
   stat->destroy = destroy;
 
-  return os;
+  return ptl;
 }