fixed.h File Reference

(r1785/r751)

Go to the source code of this file.

Defines

#define retfixed16   fixed16

Functions

fixed16 Fixed16Mul (fixed16, fixed16)
 signed multiplication
fixed16 Fixed16Div (fixed16, fixed16)
 signed division
double Fixed16ToDouble (fixed16)
 General type conversion.
fixed16 DoubleToFixed16 (double)
 General type conversion.
fixed16 Fixed16Sin (fixed16)
 General trigonometry General trigonometry.
fixed16 Fixed16Cos (fixed16)
INT32 MatrixCalc (fixed16, INT32, fixed16, INT32)
 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, fixed16)
 Method of multiplying a INT32 by a fixed point number keeping as much accuracy as possible.
INT32 LongDivFixed16 (INT32 arg, fixed16)
 Method of dividing an INT32 by a fixed point number keeping as much accuracy as possible.
INT32 MPtoPixel (INT32 arg, fixed16)
 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)
 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.

Variables

fixed16 InternalDiv32by32 (INT32, INT32)


Define Documentation

#define retfixed16   fixed16
 

Definition at line 107 of file fixed.h.


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   ) 
 

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 }

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 }


Variable Documentation

fixed16 InternalDiv32by32(INT32, INT32)
 


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