9973aaad085d — Chris Cannam 10 months ago
Experiment with using Ryu as an alternative
1 files changed, 36 insertions(+), 0 deletions(-)

A => number-string-ryu.c
A => number-string-ryu.c +36 -0
@@ 0,0 1,36 @@ 
+
+#include <ryu/ryu.h>
+
+#include <stdio.h>
+#include <stdint.h>
+#include <inttypes.h>
+
+int32_t string_from_double(char *str, int64_t sz, double d)
+{
+    /* ryu hard-codes 25 for its string allocation for double */
+    if (sz < 25) {
+        snprintf(str, sz, "#ERROR#");
+    } else {
+        d2s_buffered(d, str);
+    }
+}
+
+int32_t string_from_float(char *str, int64_t sz, float f)
+{
+    /* ryu hard-codes 16 for its string allocation for float */
+    if (sz < 16) {
+        snprintf(str, sz, "#ERROR#");
+    } else {
+        f2s_buffered(f, str);
+    }
+}
+
+int32_t string_from_int64(char *str, int64_t sz, int64_t i)
+{
+#ifdef PRId64
+    return snprintf(str, sz, "%" PRId64, i);
+#else
+    return snprintf(str, sz, "%lld", i);
+#endif
+}
+