summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/test/printf_hack.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:15:05 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:15:05 +0000
commit46651ce6fe013220ed397add242004d764fc0153 (patch)
tree6e5299f990f88e60174a1d3ae6e48eedd2688b2b /src/interfaces/ecpg/test/printf_hack.h
parentInitial commit. (diff)
downloadpostgresql-14-upstream.tar.xz
postgresql-14-upstream.zip
Adding upstream version 14.5.upstream/14.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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
+}