Index: trunk/psLib/test/image/tst_psImageStats04.c
===================================================================
--- trunk/psLib/test/image/tst_psImageStats04.c	(revision 2254)
+++ trunk/psLib/test/image/tst_psImageStats04.c	(revision 2262)
@@ -15,5 +15,5 @@
 #include <float.h>
 #include <math.h>
-#define IMAGE_SIZE 8
+#define IMAGE_SIZE 5
 #define NUM_COLS IMAGE_SIZE
 #define NUM_ROWS IMAGE_SIZE
@@ -29,5 +29,5 @@
 ((A) + (B * X) + (C * Y) + (D * X * Y) + (E * X * X) + (F * Y * Y)) \
 
-psS32 FitCheby(int numCols, int numRows)
+psS32 FitChebyF32(int numCols, int numRows)
 {
     psImage *tmpImage     = NULL;
@@ -100,10 +100,86 @@
 }
 
+psS32 FitChebyF64(int numCols, int numRows)
+{
+    psImage *tmpImage     = NULL;
+    psImage *outImage     = NULL;
+    psS32 testStatus      = true;
+    psS32 memLeaks        = 0;
+    psS32 i               = 0;
+    psS32 j               = 0;
+    psS32 currentId       = psMemGetId();
+    double chi2 = 0.0;
+
+
+    printf("psImageFitPolynomial(), psImageEvalPolynom(): (%d by %d)\n", numRows, numCols);
+
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
+
+    printPositiveTestHeader(stdout,
+                            "psImageStats functions",
+                            "psImageFitPolynomial(), psImageEvalPolynom()");
+
+    tmpImage = psImageAlloc(numCols, numRows, PS_TYPE_F64);
+    outImage = psImageAlloc(numCols, numRows, PS_TYPE_F64);
+    for (i=0;i<numRows;i++) {
+        for (j=0;j<numCols;j++) {
+            tmpImage->data.F64[i][j] = I_POLY(((double) i), ((double) j));
+        }
+    }
+
+    psPolynomial2D *chebys = psPolynomial2DAlloc(5, 5, PS_POLYNOMIAL_CHEB);
+
+    chebys = psImageFitPolynomial(chebys, tmpImage);
+
+    outImage = psImageEvalPolynomial(outImage, chebys);
+
+    chi2 = 0.0;
+    for (i=0;i<numRows;i++) {
+        for (j=0;j<numCols;j++) {
+            double expect = tmpImage->data.F64[i][j];
+            double actual = outImage->data.F64[i][j];
+            chi2+= (actual-expect) * (actual-expect);
+            if (fabs((actual - expect) / expect) > ERROR_TOL) {
+                printf("pixel [%d][%d] is %.2f should be %.2f\n", i, j, actual, expect);
+            }
+        }
+    }
+    chi2/= ((double) (numCols * numRows));
+    printf("The chi-squared per pixel is %f\n", chi2);
+
+    psFree(tmpImage);
+    psFree(outImage);
+    psFree(chebys);
+    psMemCheckCorruption(1);
+    printFooter(stdout,
+                "psImageStats functions",
+                "psImagePixelInterpolation()",
+                testStatus);
+
+    /*************************************************************************/
+    /*  Deallocate data structures                                   */
+    /*************************************************************************/
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    return(!testStatus);
+}
+
 int main()
 {
-    FitCheby(1, 1);
-    FitCheby(1, NUM_ROWS);
-    FitCheby(1, 1);
-    FitCheby(NUM_COLS, 1);
-    FitCheby(NUM_COLS, NUM_ROWS);
+    FitChebyF32(1, 1);
+    FitChebyF32(1, NUM_ROWS);
+    FitChebyF32(1, 1);
+    FitChebyF32(NUM_COLS, 1);
+    FitChebyF32(NUM_COLS, NUM_ROWS);
+    FitChebyF64(1, 1);
+    FitChebyF64(1, NUM_ROWS);
+    FitChebyF64(1, 1);
+    FitChebyF64(NUM_COLS, 1);
+    FitChebyF64(NUM_COLS, NUM_ROWS);
 }
