summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-01-23 23:36:20 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-01-23 23:36:20 +0000
commitc227f663b6285f9caa19df72baaeaa7d89cebfc7 (patch)
treeeea682107c4fb88acfa21d1886c6d14ad0e775bf
parentd2d2fcacf54d4598f01b261d3c7ca808a64af1e4 (diff)
downloadlibcss-c227f663b6285f9caa19df72baaeaa7d89cebfc7.tar.gz
libcss-c227f663b6285f9caa19df72baaeaa7d89cebfc7.tar.bz2
Ensure that we round the fractional part to nearest when converting back to decimal.
svn path=/trunk/libcss/; revision=6205
-rw-r--r--test/dump.h3
-rw-r--r--test/number.c3
2 files changed, 4 insertions, 2 deletions
diff --git a/test/dump.h b/test/dump.h
index 6bff4aa..1adfbe6 100644
--- a/test/dump.h
+++ b/test/dump.h
@@ -323,7 +323,8 @@ 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);
+ /* + 500 to ensure round to nearest (division will truncate) */
+ uint32_t fracpart = ((ABS(f) & 0x3ff) * 1000 + 500) / (1 << 10);
#undef ABS
size_t flen = 0;
char tmp[20];
diff --git a/test/number.c b/test/number.c
index 1f4f9d9..46b2fda 100644
--- a/test/number.c
+++ b/test/number.c
@@ -129,7 +129,8 @@ void print_fixed(char *buf, size_t len, fixed f)
{
#define ABS(x) ((x) < 0 ? -(x) : (x))
uint32_t uintpart = FIXTOINT(ABS(f));
- uint32_t fracpart = ((ABS(f) & 0x3ff) * 1000) / (1 << 10);
+ /* + 500 to ensure round to nearest (division will truncate) */
+ uint32_t fracpart = ((ABS(f) & 0x3ff) * 1000 + 500) / (1 << 10);
#undef ABS
size_t flen = 0;
char tmp[20];