private int doubleCompare(double d1, double d2) {
        // see if the numbers equal each other
        if (d1 == d2) {
            // these are not NaNs, and therefore we just need to check that
            // that they're not zeros, which may have different signs
            if (d1 != 0)
                return 0;

            // they're both zeros, so we compare strings to figure out
            // the significance of any signs
            return Double.toString(d1).compareTo(Double.toString(d2));
        }

        // see if d1 is NaN
        if (Double.isNaN(d1)) {
            // d1 is NaN, so see if d2 is as well
            if (Double.isNaN(d2)) {
                // they're both NaNs, so they're equal
                return 0;
            } else {
                // d1 is always bigger than d2 since it's a NaN
                return 1;
            }
        }

        // see if d2 is NaN
        if (Double.isNaN(d2)) {
            // d2 is a NaN, though d1 isn't, so d2 is always bigger
            return -1;
        }

        // if we got here then neither is a NaN, and the numbers aren't
        // equal...given those facts, basic comparison works the same in
        // java as it's defined in XMLSchema, so now we can do the simple
        // comparison and return whatever we find
        return ((d1 > d2) ? 1 : -1);
    }