@@ -135,7 +135,8 @@ class CORE_EXPORT QgsStatisticalSummary
135135
136136 /* * Returns the value of a specified statistic
137137 * @param stat statistic to return
138- * @returns calculated value of statistic
138+ * @returns calculated value of statistic. A NaN value may be returned for invalid
139+ * statistics.
139140 */
140141 double statistic ( Statistic stat ) const ;
141142
@@ -152,35 +153,42 @@ class CORE_EXPORT QgsStatisticalSummary
152153 */
153154 double sum () const { return mSum ; }
154155
155- /* * Returns calculated mean of values
156+ /* * Returns calculated mean of values. A NaN value may be returned if the mean cannot
157+ * be calculated.
156158 */
157159 double mean () const { return mMean ; }
158160
159161 /* * Returns calculated median of values. This is only calculated if Statistic::Median has
160- * been specified in the constructor or via setStatistics.
162+ * been specified in the constructor or via setStatistics. A NaN value may be returned if the median cannot
163+ * be calculated.
161164 */
162165 double median () const { return mMedian ; }
163166
164- /* * Returns calculated minimum from values.
167+ /* * Returns calculated minimum from values. A NaN value may be returned if the minimum cannot
168+ * be calculated.
165169 */
166170 double min () const { return mMin ; }
167171
168- /* * Returns calculated maximum from values.
172+ /* * Returns calculated maximum from values. A NaN value may be returned if the maximum cannot
173+ * be calculated.
169174 */
170175 double max () const { return mMax ; }
171176
172- /* * Returns calculated range (difference between maximum and minimum values).
177+ /* * Returns calculated range (difference between maximum and minimum values). A NaN value may be returned if the range cannot
178+ * be calculated.
173179 */
174- double range () const { return mMax - mMin ; }
180+ double range () const { return qIsNaN ( mMax ) || qIsNaN ( mMin ) ? std::numeric_limits< double >:: quiet_NaN () : mMax - mMin ; }
175181
176182 /* * Returns population standard deviation. This is only calculated if Statistic::StDev has
177- * been specified in the constructor or via setStatistics.
183+ * been specified in the constructor or via setStatistics. A NaN value may be returned if the standard deviation cannot
184+ * be calculated.
178185 * @see sampleStDev
179186 */
180187 double stDev () const { return mStdev ; }
181188
182189 /* * Returns sample standard deviation. This is only calculated if Statistic::StDev has
183- * been specified in the constructor or via setStatistics.
190+ * been specified in the constructor or via setStatistics. A NaN value may be returned if the standard deviation cannot
191+ * be calculated.
184192 * @see stDev
185193 */
186194 double sampleStDev () const { return mSampleStdev ; }
@@ -193,38 +201,43 @@ class CORE_EXPORT QgsStatisticalSummary
193201
194202 /* * Returns minority of values. The minority is the value with least occurances in the list
195203 * This is only calculated if Statistic::Minority has been specified in the constructor
196- * or via setStatistics.
204+ * or via setStatistics. A NaN value may be returned if the minority cannot
205+ * be calculated.
197206 * @see majority
198207 */
199208 double minority () const { return mMinority ; }
200209
201210 /* * Returns majority of values. The majority is the value with most occurances in the list
202211 * This is only calculated if Statistic::Majority has been specified in the constructor
203- * or via setStatistics.
212+ * or via setStatistics. A NaN value may be returned if the majority cannot
213+ * be calculated.
204214 * @see minority
205215 */
206216 double majority () const { return mMajority ; }
207217
208218 /* * Returns the first quartile of the values. The quartile is calculated using the
209- * "Tukey's hinges" method.
219+ * "Tukey's hinges" method. A NaN value may be returned if the first quartile cannot
220+ * be calculated.
210221 * @see thirdQuartile
211222 * @see interQuartileRange
212223 */
213224 double firstQuartile () const { return mFirstQuartile ; }
214225
215226 /* * Returns the third quartile of the values. The quartile is calculated using the
216- * "Tukey's hinges" method.
227+ * "Tukey's hinges" method. A NaN value may be returned if the third quartile cannot
228+ * be calculated.
217229 * @see firstQuartile
218230 * @see interQuartileRange
219231 */
220232 double thirdQuartile () const { return mThirdQuartile ; }
221233
222234 /* * Returns the inter quartile range of the values. The quartiles are calculated using the
223- * "Tukey's hinges" method.
235+ * "Tukey's hinges" method. A NaN value may be returned if the IQR cannot
236+ * be calculated.
224237 * @see firstQuartile
225238 * @see thirdQuartile
226239 */
227- double interQuartileRange () const { return mThirdQuartile - mFirstQuartile ; }
240+ double interQuartileRange () const { return qIsNaN ( mThirdQuartile ) || qIsNaN ( mFirstQuartile ) ? std::numeric_limits< double >:: quiet_NaN () : mThirdQuartile - mFirstQuartile ; }
228241
229242 /* * Returns the friendly display name for a statistic
230243 * @param statistic statistic to return name for
0 commit comments