Index: trunk/Ohana/src/libohana/test/print_floats.c
===================================================================
--- trunk/Ohana/src/libohana/test/print_floats.c	(revision 39040)
+++ trunk/Ohana/src/libohana/test/print_floats.c	(revision 39040)
@@ -0,0 +1,123 @@
+# include "ohana.h"
+# include "tap_ohana.h"
+
+# define NTESTS 300000
+
+void test_float (float value) {
+  char output[128], string[128];
+
+  int Noutput = sprintf_float(output, value);
+  ok (Noutput == strlen(output), "right length");
+  sprintf (string, "%+14.7e", value);
+  ok (!strcmp (output, string), "right format");
+
+  if (strcmp (output, string)) {
+    fprintf (stderr, "output: %s, string: %s\n", output, string);
+  }
+  return;
+}
+
+void test_double (double value) {
+  char output[128], string[128];
+
+  int Noutput = sprintf_double(output, value);
+  ok (Noutput == strlen(output), "right length");
+  sprintf (string, "%+21.14e", value);
+  ok (!strcmp (output, string), "right format");
+
+  if (strcmp (output, string)) {
+    fprintf (stderr, "output: %s, string: %s\n", output, string);
+  }
+  return;
+}
+
+int main (void) {
+
+  plan_tests (20);
+
+  diag ("libohana print_float.c tests");
+
+  /*** sprint_float ***/
+  if (1) {
+    int Noutput;
+    char output[128];
+
+    // do a bunch of special values:
+    Noutput = sprintf_float(output, 0.0);
+    ok (Noutput == strlen(output), "right length for 0.0");
+    
+    test_float (1.0);
+    test_float (10.0);
+    test_float (100.0);
+
+    test_float (0.1);
+    test_float (0.01);
+    test_float (0.001);
+
+    // init with a fixed seed:
+    srand48(0);
+
+    int i;
+    float value;
+    for (i = 0; i < 1000; i++) {
+      value = 1e7 * (drand48() - 0.5);
+      test_float (value);
+    }
+
+    INITTIME;
+    for (i = 0; i < NTESTS; i++) {
+      value = 1e7 * (drand48() - 0.5);
+      sprintf_float (output, value);
+    }
+    MARKTIME("convert %d floats with sprintf_float: %f\n", NTESTS, dtime);
+
+    gettimeofday (&startTimer, (void *) NULL);
+    for (i = 0; i < NTESTS; i++) {
+      value = 1e7 * (drand48() - 0.5);
+      sprintf (output, "%+14.7e", value);
+    }
+    MARKTIME("convert %d float with sprintf: %f\n", NTESTS, dtime);
+  }
+  
+  /*** sprint_double ***/
+  if (1) {
+    int Noutput;
+    char output[128];
+
+    // do a bunch of special values:
+    Noutput = sprintf_double(output, 0.0);
+    ok (Noutput == strlen(output), "right length for 0.0");
+    
+    test_double (1.0);
+    test_double (10.0);
+    test_double (100.0);
+    test_double (0.1);
+    test_double (0.01);
+    test_double (0.001);
+
+    // init with a fixed seed:
+    srand48(0);
+    
+    int i;
+    double value;
+    for (i = 0; i < 1000; i++) {
+      value = 1e15 * (drand48() - 0.5);
+      test_double (value);
+    }
+
+    INITTIME;
+    for (i = 0; i < NTESTS; i++) {
+      value = 1e15 * (drand48() - 0.5);
+      sprintf_double (output, value);
+    }
+    MARKTIME("convert %d doubles with sprintf_double: %f\n", NTESTS, dtime);
+
+    gettimeofday (&startTimer, (void *) NULL);
+    for (i = 0; i < NTESTS; i++) {
+      value = 1e15 * (drand48() - 0.5);
+      sprintf (output, "%+21.14e", value);
+    }
+    MARKTIME("convert %d doubles with sprintf: %f\n", NTESTS, dtime);
+  }
+  return exit_status();
+}
