Index: trunk/psLib/src/dataManip/psStats.c
===================================================================
--- trunk/psLib/src/dataManip/psStats.c	(revision 2342)
+++ trunk/psLib/src/dataManip/psStats.c	(revision 2343)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.93 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-11-12 19:36:07 $
+ *  @version $Revision: 1.94 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-11-12 19:50:34 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -992,5 +992,18 @@
                        float getThisValue)
 {
+    PS_POLY_CHECK_NULL(myPoly, NAN);
     PS_FLOAT_COMPARE(rangeLow, rangeHigh, NAN);
+    // We ensure that the requested f(y) value, which is getThisValue, is
+    // falls within the range of y-values of the polynomial "myPoly" in the
+    // specified x-range (rangeLow:rangeHigh).
+    float fLo = psPolynomial1DEval(rangeLow, myPoly);
+    float fHi = psPolynomial1DEval(rangeHigh, myPoly);
+    if (!((fLo <= getThisValue) && (fHi >= getThisValue))) {
+        psError(PS_ERR_UNKNOWN,
+                true,
+                psStats_STATS_POLY_MEDIAN_OUT_OF_RANGE);
+        return(NAN);
+    }
+
     psS32 numIterations = 0;
     float midpoint = 0.0;
@@ -1073,4 +1086,10 @@
         // Determine the coefficients of the polynomial.
         myPoly = psVectorFitPolynomial1D(myPoly, x, y, yErr);
+        if (myPoly == NULL) {
+            psError(PS_ERR_UNEXPECTED_NULL,
+                    false,
+                    psStats_STATS_FIT_QUADRATIC_POLYNOMIAL_1D_FIT);
+            return(NAN);
+        }
         // Call p_ps1DPolyMedian(), which does a binary search on the
         // polynomial, looking for the value x such that f(x) = yVal
