fixed.cpp File Reference

(r1785/r1282)

#include "camtypes.h"

Go to the source code of this file.

Functions

fixed16 Fixed16Mul (fixed16 a, fixed16 b)
 signed multiplication
fixed16 Fixed16Div (fixed16 a, fixed16 b)
 signed division
fixed16 InternalDiv32by32 (INT32 a, INT32 b)
 Obtain a fixed-point representation of the ratio between two signed numbers.
double Fixed16ToDouble (fixed16 a)
 General type conversion.
fixed16 DoubleToFixed16 (double arg)
 General type conversion.
fixed16 Fixed16Sin (fixed16 arg)
 General trigonometry General trigonometry.
fixed16 Fixed16Cos (fixed16 arg)
INT32 MatrixCalc (fixed16 fix1, INT32 l1, fixed16 fix2, INT32 l2)
 Matrix multiply primitive done using intermediate 64-bit results so accuracy is maintained. Special cases are when fix1 or fix2 are 0.0 or 1.0 as multiplications may be avoided. Note that the result is rounded to the nearest integer.
INT32 LongMulFixed16 (INT32 arg, fixed16 fix)
 Method of multiplying a INT32 by a fixed point number keeping as much accuracy as possible.
INT32 LongDivFixed16 (INT32 arg, fixed16 fix)
 Method of dividing an INT32 by a fixed point number keeping as much accuracy as possible.
INT32 MPtoPixel (INT32 arg, fixed16 fix)
 Method of dividing a INT32 by a fixed point number keeping as much accuracy as possible. This version will Round any fractional result to the NEAREST whole value. It is used for scaling Millipoints to Whole Pixels. Assumptions:Fix is +ve.
INT32 MPtoOS256 (INT32 arg, fixed16 fix)
 Method of dividing a INT32 by a fixed point number keeping as much accuracy as possible. This version will convert the MP value to 256ths of a Pixel.


Function Documentation

fixed16 DoubleToFixed16 double  arg  ) 
 

General type conversion.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/5/93
Parameters:
double-precision argument [INPUTS]
None [OUTPUTS]
Returns:
FIXED16 value

Errors: None (overflow will cause exception)

This is done by taking the arg and multiplying it by 65536, then converting to integer.

Definition at line 234 of file fixed.cpp.

00235 {
00236     fixed16 result ;
00237 #if 0//defined(_M_IX86)
00238     //
00239     // This avoids the slow fix operation. Add a large number so that
00240     // the double always has the same exponent and the mantissa becomes,
00241     // in affect, a fixed point value with the value we want in the
00242     // bottom 32 bits.
00243     //
00244     // Note that we are relying on the compiler to convert this to
00245     // efficient code.
00246     //
00247     // TODO: Test!
00248     //
00249     static const double fFix = (XLONG)3<<(DBL_MANT_DIG-16-2);
00250     double F = arg+fFix;
00251     result.all = (INT32&)F ;
00252 #else
00253     result.all = INT32(arg*(1<<16)) ;
00254 #endif
00255     return result ;
00256 }

fixed16 Fixed16Cos fixed16  arg  ) 
 

Definition at line 298 of file fixed.cpp.

00299 {
00300     return DoubleToFixed16( cos( double(2.6631610900792382460383465095346e-7) * arg.MakeDouble() ) );
00301 }

fixed16 Fixed16Div fixed16  a,
fixed16  b
 

signed division

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
10/5/93
Parameters:
two fixed16s [INPUTS]
None [OUTPUTS]
Returns:
FIXED16 result (arg1 / arg2) Scope: Only to be used in the FIXED16 class.

Errors: None (no overflow checks). No rounding either (should it?) Overflow will cause a DIV0 exception, as will divide by zero

Definition at line 147 of file fixed.cpp.

00148 {
00149     fixed16 result ;
00150 //  result.all = MulDiv(a.all,1<<16,b.all) ;
00151     result.all = INT32(((xlong)a.all<<16)/b.all) ;
00152     return result ;
00153 }

fixed16 Fixed16Mul fixed16  a,
fixed16  b
 

signed multiplication

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
10/5/93
Parameters:
two fixed16s [INPUTS]
None [OUTPUTS]
Returns:
FIXED16 result (arg1 * arg2) Scope: Only to be used in the FIXED16 class.

Errors: None (no overflow checks). Rounds

Definition at line 122 of file fixed.cpp.

00123 {
00124     fixed16 result ;
00125 //  result.all = INT32(Int32x32To64(a.all,b.all)+0x8000>>16) ;
00126     result.all = INT32(((xlong)a.all*b.all+0x8000) >> 16) ;
00127     return result ;
00128 }

fixed16 Fixed16Sin fixed16  arg  ) 
 

General trigonometry General trigonometry.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/5/93
Parameters:
FIXED16 argument in degrees [INPUTS]
None [OUTPUTS]
Returns:
FIXED16 result Scope: Only to be used in the FIXED16 class.

Errors: None

Definition at line 293 of file fixed.cpp.

00294 {
00295     return DoubleToFixed16( sin( double(2.6631610900792382460383465095346e-7) * arg.MakeDouble() ) );
00296 }

double Fixed16ToDouble fixed16  a  ) 
 

General type conversion.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/5/93
Parameters:
FIXED16 argument [INPUTS]
None [OUTPUTS]
Returns:
double-precision value Scope: Only to be used in the FIXED16 class.

Errors: None

This code relies on the compiler efficiently replacing the division by a multiplication of the reciprical.

Definition at line 212 of file fixed.cpp.

00213 {
00214     return (double)a.all/(1<<16) ;
00215 }

fixed16 InternalDiv32by32 INT32  a,
INT32  b
 

Obtain a fixed-point representation of the ratio between two signed numbers.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/5/93
Parameters:
two signed 32-bit numbers [INPUTS]
None [OUTPUTS]
Returns:
FIXED16 result of arg1/arg2 Scope: Private to the CCMATHS library.

Errors: None. Div0 and overflow will create a div0 exception.

Awooga! Awooga! Do not call this function directly - it returns a INT32 and is meant to be used only in the C++ wrapper (i.e. it returns the value << 16)

This is done by multiplying arg1 by 65536, then doing a 64-bit/32-bit division

Curiously enough, this function is 100% the same as Fixed16Div. When you think about it, its not really that curious as both args are 65536 times bigger than the FIXED16 versions, and x/y is identical to x*65536/y*65536.

Definition at line 184 of file fixed.cpp.

00185 {
00186     fixed16 result ;
00187 //  result.all = MulDiv(a.all,1<<16,b.all) ;
00188     result.all = INT32( ( (xlong)a << 16 ) / b );
00189     return result ;
00190 }

INT32 LongDivFixed16 INT32  arg,
fixed16  fix
 

Method of dividing an INT32 by a fixed point number keeping as much accuracy as possible.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/7/93
Parameters:
one FIXED16, one INT32 [INPUTS]
None [OUTPUTS]
Returns:
INT32 result of arg / fix

Errors: None (overflow ignored). Div0 and Overflow will take exception.

Definition at line 367 of file fixed.cpp.

00368 {
00369     return INT32(((xlong)arg<<16)/fix.all) ;
00370 }

INT32 LongMulFixed16 INT32  arg,
fixed16  fix
 

Method of multiplying a INT32 by a fixed point number keeping as much accuracy as possible.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/5/93
Parameters:
one FIXED16, one INT32 [INPUTS]
None [OUTPUTS]
Returns:
INT32 result of fix * arg Scope: Only to be used in the Matrix class.

Errors: None (overflow ignored).

Definition at line 346 of file fixed.cpp.

00347 {
00348     return INT32( ((xlong)arg * fix.all + 0x8000) >> 16 );
00349 }

INT32 MatrixCalc fixed16  fix1,
INT32  l1,
fixed16  fix2,
INT32  l2
 

Matrix multiply primitive done using intermediate 64-bit results so accuracy is maintained. Special cases are when fix1 or fix2 are 0.0 or 1.0 as multiplications may be avoided. Note that the result is rounded to the nearest integer.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/5/93
Parameters:
two FIXED16s, two INT32s [INPUTS]
None [OUTPUTS]
Returns:
INT32 result of fix1*l1 + fix2*l2 Scope: Only to be used in the Matrix classes.

Errors: None (overflow ignored).

Definition at line 323 of file fixed.cpp.

00324 {
00325     return INT32( ( (xlong)fix1.all * l1 + (xlong)fix2.all * l2 ) >> 16 );
00326 }

INT32 MPtoOS256 INT32  arg,
fixed16  fix
 

Method of dividing a INT32 by a fixed point number keeping as much accuracy as possible. This version will convert the MP value to 256ths of a Pixel.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/9/93
Parameters:
one FIXED16, one INT32 [INPUTS]
None [OUTPUTS]
Returns:
INT32 result of arg / fix

Errors: None (overflow ignored). Div0 and Overflow will take exception.

Definition at line 425 of file fixed.cpp.

00426 {
00427     return INT32(((xlong)arg<<24)/fix.all) ;
00428 }

INT32 MPtoPixel INT32  arg,
fixed16  fix
 

Method of dividing a INT32 by a fixed point number keeping as much accuracy as possible. This version will Round any fractional result to the NEAREST whole value. It is used for scaling Millipoints to Whole Pixels. Assumptions:Fix is +ve.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/9/93
Parameters:
one FIXED16, one INT32 [INPUTS]
None [OUTPUTS]
Returns:
INT32 result of arg / fix

Errors: None (overflow ignored). Div0 and Overflow will take exception.

Definition at line 392 of file fixed.cpp.

00393 {
00394     if ( arg<0 )
00395         return INT32((((xlong)arg<<16)-(fix.all>>1))/fix.all) ;
00396     else
00397         return INT32((((xlong)arg<<16)+(fix.all>>1))/fix.all) ;
00398 
00399 // Gavin says (07/03/2006) the following would be more accurate so long as
00400 // we could guarantee that fix.all<<1 does not overflow:
00401 //  if ( arg<0 )
00402 //      return INT32((((xlong)arg<<17)-fix.all))/(fix.all<<1)) ;
00403 //  else
00404 //      return INT32((((xlong)arg<<17)+fix.all))/(fix.all<<1)) ;
00405 }


Generated on Sat Nov 10 03:49:09 2007 for Camelot by  doxygen 1.4.4