[base] Remove truncation in `FT_DivFix'. * src/base/ftcalc.c (FT_DivFix): Updated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
diff --git a/ChangeLog b/ChangeLog
index 4ed20c9..8f25f1e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-08-18 Alexei Podtelezhnikov <apodtele@gmail.com>
+
+ [base] Remove truncation in `FT_DivFix'.
+
+ * src/base/ftcalc.c (FT_DivFix): Updated.
+
2014-08-14 Alexei Podtelezhnikov <apodtele@gmail.com>
Minor refactoring.
diff --git a/src/base/ftcalc.c b/src/base/ftcalc.c
index 27eee57..27e9e07 100644
--- a/src/base/ftcalc.c
+++ b/src/base/ftcalc.c
@@ -247,11 +247,10 @@
FT_DivFix( FT_Long a,
FT_Long b )
{
- FT_Int32 s;
- FT_UInt32 q;
+ FT_Int s = 1;
+ FT_Long q;
- s = 1;
if ( a < 0 )
{
a = -a;
@@ -268,9 +267,9 @@
q = 0x7FFFFFFFL;
else
/* compute result directly */
- q = (FT_UInt32)( ( ( (FT_UInt64)a << 16 ) + ( b >> 1 ) ) / b );
+ q = (FT_Long)( ( ( (FT_UInt64)a << 16 ) + ( b >> 1 ) ) / b );
- return ( s < 0 ? -(FT_Long)q : (FT_Long)q );
+ return ( s < 0 ? -q : q );
}
@@ -564,23 +563,23 @@
FT_DivFix( FT_Long a,
FT_Long b )
{
- FT_Int32 s;
- FT_UInt32 q;
+ FT_Long s;
+ FT_Long q;
/* XXX: this function does not allow 64-bit arguments */
- s = (FT_Int32)a; a = FT_ABS( a );
- s ^= (FT_Int32)b; b = FT_ABS( b );
+ s = a; a = FT_ABS( a );
+ s ^= b; b = FT_ABS( b );
- if ( (FT_UInt32)b == 0 )
+ if ( b == 0 )
{
/* check for division by 0 */
- q = (FT_UInt32)0x7FFFFFFFL;
+ q = 0x7FFFFFFFL;
}
else if ( ( a >> 16 ) == 0 )
{
/* compute result directly */
- q = (FT_UInt32)( ( (FT_ULong)a << 16 ) + ( b >> 1 ) ) / (FT_UInt32)b;
+ q = (FT_Long)( ( ( (FT_ULong)a << 16 ) + ( b >> 1 ) ) / b );
}
else
{
@@ -593,10 +592,10 @@
temp2.hi = 0;
temp2.lo = (FT_UInt32)( b >> 1 );
FT_Add64( &temp, &temp2, &temp );
- q = ft_div64by32( temp.hi, temp.lo, (FT_Int32)b );
+ q = (FT_Long)ft_div64by32( temp.hi, temp.lo, (FT_Int32)b );
}
- return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q );
+ return ( s < 0 ? -q : q );
}