summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-01-23 20:44:32 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-01-23 20:44:32 +0000
commit6d512fd22fdda551aeb57a6b1a6534b187a64dcb (patch)
tree04ce798bcd0986deb741cc9085187c92bbb9df87
parent0e7b435066b83f933e2fc1a9887435469ce21051 (diff)
downloadlibcss-6d512fd22fdda551aeb57a6b1a6534b187a64dcb.tar.gz
libcss-6d512fd22fdda551aeb57a6b1a6534b187a64dcb.tar.bz2
Use our own fixed point value printing routine rather than relying on sprintf's %f modifier to do the right thing
svn path=/trunk/libcss/; revision=6193
-rw-r--r--test/dump.h57
1 files changed, 56 insertions, 1 deletions
diff --git a/test/dump.h b/test/dump.h
index c8977f3..7c8c76d 100644
--- a/test/dump.h
+++ b/test/dump.h
@@ -319,12 +319,67 @@ static const char *opcode_names[] = {
*/
static const char *sides[] = { "top", "right", "bottom", "left" };
+static void dump_fixed(fixed f, char **ptr)
+{
+#define ABS(x) ((x) < 0 ? -(x) : (x))
+ uint32_t uintpart = FIXTOINT(ABS(f));
+ uint32_t fracpart = ((ABS(f) & 0x3ff) * 1000) / (1 << 10);
+#undef ABS
+ size_t flen = 0;
+ char tmp[20];
+ size_t tlen = 0;
+ char *buf = *ptr;
+
+ if (f < 0) {
+ buf[0] = '-';
+ buf++;
+ }
+
+ do {
+ tmp[tlen] = "0123456789"[uintpart % 10];
+ tlen++;
+
+ uintpart /= 10;
+ } while (tlen < 20 && uintpart != 0);
+
+ while (tlen > 0) {
+ buf[0] = tmp[--tlen];
+ buf++;
+ }
+
+ buf[0] = '.';
+ buf++;
+
+ do {
+ tmp[tlen] = "0123456789"[fracpart % 10];
+ tlen++;
+
+ fracpart /= 10;
+ } while (tlen < 20 && fracpart != 0);
+
+ while (tlen > 0) {
+ buf[0] = tmp[--tlen];
+ buf++;
+ flen++;
+ }
+
+ while (flen < 3) {
+ buf[0] = '0';
+ buf++;
+ flen++;
+ }
+
+ buf[0] = '\0';
+
+ *ptr = buf;
+}
+
static void dump_number(fixed val, char **ptr)
{
if (INTTOFIX(FIXTOINT(val)) == val)
*ptr += sprintf(*ptr, "%d", FIXTOINT(val));
else
- *ptr += sprintf(*ptr, "%f", FIXTOFLT(val));
+ dump_fixed(val, ptr);
}
static void dump_unit(fixed val, uint32_t unit, char **ptr)