#686 BoxAndWhiskerCalculator computes max/min of NaNs incorrectly

General (896)
Alex Mont

If an array consisting of partially NaNs is passed to
the BoxAndWhiskerCalculator, the computed "max" and
"min" will be NaN. The cause of this error is that NaNs
are checked for using "minRegularValue == Double.NaN"
(lines 114 and 120 of
which always returns false because nothing is equal to
Double.NaN. (The correct way to check is to use

The following is a test case that demonstrates the
error. It prints "NaN NaN".

import java.util.ArrayList;
import org.jfree.data.statistics.*;
import java.lang.Double;

ArrayList theList = new ArrayList(5);
theList.add(0, new Double(1.0));
theList.add(1, new Double(2.0));
theList.add(2, new Double(Double.NaN));
theList.add(3, new Double(3.0));
theList.add(4, new Double(4.0));
BoxAndWhiskerItem theItem =
Number minVal = theItem.getMinRegularValue();
Number maxVal = theItem.getMaxRegularValue();
System.out.println(minVal.toString() + " " +


Note that even if the checks on lines 114 and 120 were
chenged to use Double.isNaN(), this would still be
incorrect, since when going through the list it would
put the NaN in minRegularValue and maxRegularValue and
then replace it when the net element in the list,
effectively removing all prior elements in the list
from consideration to be the minimum or the maximum. In
this case, the function would print "3.0 4.0", instead
of "1.0 4.0" like it should.


  • David Gilbert

    David Gilbert - 2006-11-10

    Logged In: YES

    Hmmm...one of the more embarassing bugs! I'll get that
    fixed before 1.0.3 goes out.


    Dave Gilbert
    JFreeChart Project Leader

  • David Gilbert

    David Gilbert - 2006-11-10
    • labels: --> General
    • milestone: --> 1.0.x
    • priority: 5 --> 9
    • assigned_to: nobody --> mungady
  • David Gilbert

    David Gilbert - 2006-11-16
    • status: open --> closed
  • David Gilbert

    David Gilbert - 2006-11-16

    Logged In: YES
    Originator: NO

    Wow, it turned out to be a real rats nest...I've 'fixed' the problem by having the code strip out null and NaN items from the list. Maybe the whole approach needs rethinking, but not right now...closing as fixed.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks