Index: /trunk/psLib/src/dataManip/psDataManipErrors.dat
===================================================================
--- /trunk/psLib/src/dataManip/psDataManipErrors.dat	(revision 2342)
+++ /trunk/psLib/src/dataManip/psDataManipErrors.dat	(revision 2343)
@@ -27,4 +27,6 @@
 psStats_STATS_SAMPLE_MEDIAN_SORT_PROBLEM            Failed to sort input data.
 psStats_STATS_VECTOR_BIN_DISECT_PROBLEM		Failed to determine the bin number of a data element.
+psStats_STATS_FIT_QUADRATIC_POLYNOMIAL_1D_FIT Failed to fit a 1-dimensional polynomial to the three specified data points.  Returning NAN.
+psStats_STATS_POLY_MEDIAN_OUT_OF_RANGE The requested y-value does not fall with the specified range of x-values.  Returning NAN.
 #
 psFunctions_INVALID_POLYNOMIAL_TYPE    Unknown polynomial type 0x%x found.  Evaluation failed.
Index: /trunk/psLib/src/dataManip/psDataManipErrors.h
===================================================================
--- /trunk/psLib/src/dataManip/psDataManipErrors.h	(revision 2342)
+++ /trunk/psLib/src/dataManip/psDataManipErrors.h	(revision 2343)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-11-11 20:13:57 $
+ *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-11-12 19:50:34 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -47,4 +47,6 @@
 #define PS_ERRORTEXT_psStats_STATS_SAMPLE_MEDIAN_SORT_PROBLEM "Failed to sort input data."
 #define PS_ERRORTEXT_psStats_STATS_VECTOR_BIN_DISECT_PROBLEM "Failed to determine the bin number of a data element."
+#define PS_ERRORTEXT_psStats_STATS_FIT_QUADRATIC_POLYNOMIAL_1D_FIT "Failed to fit a 1-dimensional polynomial to the three specified data points.  Returning NAN."
+#define PS_ERRORTEXT_psStats_STATS_POLY_MEDIAN_OUT_OF_RANGE "The requested y-value does not fall with the specified range of x-values.  Returning NAN."
 #define PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE "Unknown polynomial type 0x%x found.  Evaluation failed."
 #define PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED "Input psVector type, %s, is not supported."
Index: /trunk/psLib/src/dataManip/psFunctions.c
===================================================================
--- /trunk/psLib/src/dataManip/psFunctions.c	(revision 2342)
+++ /trunk/psLib/src/dataManip/psFunctions.c	(revision 2343)
@@ -7,6 +7,6 @@
  *  polynomials.  It also contains a Gaussian functions.
  *
- *  @version $Revision: 1.63 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-11-11 19:32:20 $
+ *  @version $Revision: 1.64 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-11-12 19:50:34 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -1169,5 +1169,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1207,5 +1207,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1260,5 +1260,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1324,5 +1324,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1564,5 +1564,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1603,5 +1603,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1657,5 +1657,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1721,5 +1721,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
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
Index: /trunk/psLib/src/math/psPolynomial.c
===================================================================
--- /trunk/psLib/src/math/psPolynomial.c	(revision 2342)
+++ /trunk/psLib/src/math/psPolynomial.c	(revision 2343)
@@ -7,6 +7,6 @@
  *  polynomials.  It also contains a Gaussian functions.
  *
- *  @version $Revision: 1.63 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-11-11 19:32:20 $
+ *  @version $Revision: 1.64 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-11-12 19:50:34 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -1169,5 +1169,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1207,5 +1207,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1260,5 +1260,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1324,5 +1324,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1564,5 +1564,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1603,5 +1603,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1657,5 +1657,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1721,5 +1721,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
Index: /trunk/psLib/src/math/psSpline.c
===================================================================
--- /trunk/psLib/src/math/psSpline.c	(revision 2342)
+++ /trunk/psLib/src/math/psSpline.c	(revision 2343)
@@ -7,6 +7,6 @@
  *  polynomials.  It also contains a Gaussian functions.
  *
- *  @version $Revision: 1.63 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-11-11 19:32:20 $
+ *  @version $Revision: 1.64 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-11-12 19:50:34 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -1169,5 +1169,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1207,5 +1207,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1260,5 +1260,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1324,5 +1324,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1564,5 +1564,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1603,5 +1603,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1657,5 +1657,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
@@ -1721,5 +1721,5 @@
                 myPoly->type);
     }
-    return(0.0);
+    return(NAN);
 }
 
Index: /trunk/psLib/src/math/psStats.c
===================================================================
--- /trunk/psLib/src/math/psStats.c	(revision 2342)
+++ /trunk/psLib/src/math/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
