summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/test/printf_hack.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/ecpg/test/printf_hack.h')
-rw-r--r--src/interfaces/ecpg/test/printf_hack.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/interfaces/ecpg/test/printf_hack.h b/src/interfaces/ecpg/test/printf_hack.h
new file mode 100644
index 0000000..ef584c0
--- /dev/null
+++ b/src/interfaces/ecpg/test/printf_hack.h
@@ -0,0 +1,29 @@
+/*
+ * print_double(x) has the same effect as printf("%g", x), but is intended
+ * to produce the same formatting across all platforms.
+ */
+static void
+print_double(double x)
+{
+#ifdef WIN32
+ /* Change Windows' 3-digit exponents to look like everyone else's */
+ char convert[128];
+ int vallen;
+
+ sprintf(convert, "%g", x);
+ vallen = strlen(convert);
+
+ if (vallen >= 6 &&
+ convert[vallen - 5] == 'e' &&
+ convert[vallen - 3] == '0')
+ {
+ convert[vallen - 3] = convert[vallen - 2];
+ convert[vallen - 2] = convert[vallen - 1];
+ convert[vallen - 1] = '\0';
+ }
+
+ printf("%s", convert);
+#else
+ printf("%g", x);
+#endif
+}