aboutsummaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorFranklin Wei <me@fwei.tk>2017-08-17 15:27:52 -0400
committerFranklin Wei <franklin@rockbox.org>2020-12-07 19:27:19 -0500
commitb1f691f2deb0b59c6e237241e1995c5d95f37ffa (patch)
tree499df3c5baf7fbb9943909f0eb4d48db386b444c /misc.c
parentb4b86bbdbeb99c9fd9cfa6b61454047eb5e8fe20 (diff)
downloadpuzzles-b1f691f2deb0b59c6e237241e1995c5d95f37ffa.zip
puzzles-b1f691f2deb0b59c6e237241e1995c5d95f37ffa.tar.gz
puzzles-b1f691f2deb0b59c6e237241e1995c5d95f37ffa.tar.bz2
puzzles-b1f691f2deb0b59c6e237241e1995c5d95f37ffa.tar.xz
Introduce ftoa() as a replacement for the %g format specifier
Not all platforms support printing floats, this is a more portable (if uglier) way.
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/misc.c b/misc.c
index bb9019e..ed31acb 100644
--- a/misc.c
+++ b/misc.c
@@ -402,6 +402,12 @@ void copy_left_justified(char *buf, size_t sz, const char *str)
buf[sz - 1] = 0;
}
+/* another kludge for platforms without %g support in *printf() */
+int ftoa(char *buf, float f)
+{
+ return sprintf(buf, "%d.%06d", (int)f, abs((int)((f - (int)f)*1e6)));
+}
+
/* Returns a dynamically allocated label for a generic button.
* Game-specific buttons should go into the `label' field of key_label
* instead. */