diff options
Diffstat (limited to 'include/libcss/fpmath.h')
-rw-r--r-- | include/libcss/fpmath.h | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/include/libcss/fpmath.h b/include/libcss/fpmath.h index bed5ee6..eec40b3 100644 --- a/include/libcss/fpmath.h +++ b/include/libcss/fpmath.h @@ -99,10 +99,12 @@ css_float_to_fixed(const float a) { float xx = a * (float) (1 << CSS_RADIX_POINT); if (xx < INT_MIN) - xx = INT_MIN; + return INT_MIN; - if (xx > INT_MAX) - xx = INT_MAX; + /* Conversion from int to float changes value from + * 2147483647 to 2147483648, so we use >= instead of >. */ + if (xx >= (float)INT_MAX) + return INT_MAX; return (css_fixed) xx; } @@ -128,6 +130,8 @@ css_float_to_fixed(const float a) { /* truncate a fixed point value */ #define TRUNCATEFIX(a) (a & ~((1 << CSS_RADIX_POINT)- 1 )) +/* get fractional component of a fixed point value */ +#define FIXFRAC(a) (a & ((1 << CSS_RADIX_POINT)- 1 )) /* Useful values */ #define F_PI_2 0x00000648 /* 1.5708 (PI/2) */ |