X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Fhistogram.c;h=3c88c3858f61c6b1c2230843a7b9151a47902956;hb=b1b30577f94f321a2e7dca1e5cb1e12ef38c6310;hp=67079398d169ec58737c6f3b94a7d243b9fc8516;hpb=9a331fe64eb814ae5c1322e21717a04fb254bf65;p=pspp diff --git a/src/math/histogram.c b/src/math/histogram.c index 67079398d1..3c88c3858f 100644 --- a/src/math/histogram.c +++ b/src/math/histogram.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2004, 2008 Free Software Foundation, Inc. + Copyright (C) 2004, 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 @@ -19,6 +19,7 @@ #include #include +#include #include #include "chart-geometry.h" @@ -28,7 +29,8 @@ void histogram_add (struct histogram *h, double y, double c) { - ((struct statistic *)h)->accumulate ((struct statistic *) h, NULL, c, 0, y); + struct statistic *stat = &h->parent; + stat->accumulate (stat, NULL, c, 0, y); } @@ -36,7 +38,7 @@ histogram_add (struct histogram *h, double y, double c) static void acc (struct statistic *s, const struct ccase *cx UNUSED, double c, double cc UNUSED, double y) { - struct histogram *hist = (struct histogram *) s; + struct histogram *hist = UP_CAST (s, struct histogram, parent); gsl_histogram_accumulate (hist->gsl_hist, y, c); } @@ -45,17 +47,17 @@ acc (struct statistic *s, const struct ccase *cx UNUSED, double c, double cc UNU static void destroy (struct statistic *s) { - struct histogram *h = (struct histogram *) s; + struct histogram *h = UP_CAST (s, struct histogram, parent); gsl_histogram_free (h->gsl_hist); free (s); } -struct statistic * +struct histogram * histogram_create (int bins, double min, double max) { struct histogram *h = xmalloc (sizeof *h); - struct statistic *stat = (struct statistic *) h; + struct statistic *stat = &h->parent; double upper_limit, lower_limit; double bin_width = chart_rounded_tick ((max - min) / (double) bins); @@ -78,6 +80,6 @@ histogram_create (int bins, double min, double max) stat->accumulate = acc; stat->destroy = destroy; - return stat; + return h; }