1 // This may look like C code, but it is really -*- C++ -*-
3 Copyright (C) 1988 Free Software Foundation
4 written by Dirk Grunwald (grunwald@cs.uiuc.edu)
6 This file is part of the GNU C++ Library. This library is free
7 software; you can redistribute it and/or modify it under the terms of
8 the GNU Library General Public License as published by the Free
9 Software Foundation; either version 2 of the License, or (at your
10 option) any later version. This library is distributed in the hope
11 that it will be useful, but WITHOUT ANY WARRANTY; without even the
12 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the GNU Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include <simgear_config.h>
25 #include "SGSmplhist.hxx"
33 #define HUGE_VAL DBL_MAX
37 const int SampleHistogramMinimum = -2;
38 const int SampleHistogramMaximum = -1;
40 SampleHistogram::SampleHistogram (double low, double high, double width)
51 width = (high - low) / 10;
54 howManyBuckets = int ((high - low) / width) + 2;
55 bucketCount = new int[howManyBuckets];
56 bucketLimit = new double[howManyBuckets];
58 for (int i = 0; i < howManyBuckets; i++)
64 bucketLimit[howManyBuckets - 1] = HUGE_VAL; /* from math.h */
67 SampleHistogram::~SampleHistogram ()
69 if (howManyBuckets > 0)
76 void SampleHistogram::operator += (double value)
79 for (i = 0; i < howManyBuckets; i++)
81 if (value < bucketLimit[i])
85 this->SampleStatistic::operator += (value);
88 int SampleHistogram::similarSamples (double d)
91 for (i = 0; i < howManyBuckets; i++)
93 if (d < bucketLimit[i])
94 return (bucketCount[i]);
99 void SampleHistogram::printBuckets (std::ostream & s)
101 for (int i = 0; i < howManyBuckets; i++)
103 if (bucketLimit[i] >= HUGE_VAL)
105 s << "< max : " << bucketCount[i] << "\n";
109 s << "< " << bucketLimit[i] << " : " << bucketCount[i] << "\n";
114 void SampleHistogram::reset ()
116 this->SampleStatistic::reset ();
117 if (howManyBuckets > 0)
119 for (register int i = 0; i < howManyBuckets; i++)