From 404bd07f934bd109901d7a9e8a903c10995ff327 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Mon, 24 Nov 2008 11:45:04 +0000 Subject: Fix rounding when fractional part is close to 1. Add testcase to exercise this. svn path=/trunk/libcss/; revision=5766 --- src/utils/utils.h | 7 ++++--- test/data/number/number.dat | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/utils/utils.h b/src/utils/utils.h index f1ab6d7..333a33f 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -106,9 +106,10 @@ static inline fixed number_from_css_string(const css_string *string, len--; } fracpart = ((1 << 10) * fracpart + pwr/2) / pwr; - /* Extra paranoid clamp to maximum fractional part */ - if (fracpart >= (1 << 10)) - fracpart = (1 << 10) - 1; + if (fracpart >= (1 << 10)) { + intpart++; + fracpart &= (1 << 10) - 1; + } } /* If the intpart is larger than we can represent, diff --git a/test/data/number/number.dat b/test/data/number/number.dat index a8c9cae..48ecc20 100644 --- a/test/data/number/number.dat +++ b/test/data/number/number.dat @@ -132,3 +132,9 @@ x 0.124 #reset +#data +0.999512 +#expected +1.000 +#reset + -- cgit v1.2.3