fix24.h File Reference

(r1785/r751)

Go to the source code of this file.

Defines

#define retfixed24   fixed24

Functions

fixed24 Fixed24Mul (fixed24, fixed24)
 signed multiplication
fixed24 Fixed24Div (fixed24, fixed24)
 signed division
double Fixed24ToDouble (fixed24)
 General type conversion.
fixed24 DoubleToFixed24 (double)
 General type conversion.


Define Documentation

#define retfixed24   fixed24
 

Definition at line 107 of file fix24.h.


Function Documentation

fixed24 DoubleToFixed24 double  arg  ) 
 

General type conversion.

Author:
Gavin_Theobald (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/6/2005
Parameters:
double-precision argument [INPUTS]
None [OUTPUTS]
Returns:
FIXED24 value

Errors: None (overflow will cause exception)

Definition at line 207 of file fix24.cpp.

00208 {
00209     fixed24 result ;
00210 #if 0 //defined(_M_IX86)
00211     //
00212     // This avoids the slow fix operation. Add a large number so that
00213     // the double always has the same exponent and the mantissa becomes,
00214     // in affect, a fixed point value with the value we want in the
00215     // bottom 32 bits.
00216     //
00217     // Note that we are relying on the compiler to convert this to
00218     // efficient code.
00219     //
00220     // TODO: Test!
00221     //
00222     static const double fFix = (XLONG)3<<(DBL_MANT_DIG-24-2);
00223     double F = arg+fFix;
00224     result.all = (INT32&)F ;
00225 #else
00226     result.all = INT32(arg*(1<<24)) ;
00227 #endif
00228     return result ;
00229 }

fixed24 Fixed24Div fixed24  a,
fixed24  b
 

signed division

Author:
Gavin_Theobald (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/6/2005
Parameters:
two fixed24s [INPUTS]
None [OUTPUTS]
Returns:
FIXED24 result (arg1 / arg2) Scope: Only to be used in the FIXED24 class.

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

Note that this is not very efficient as it forces a multiply that could instead be performed by a shift. The alternative is to use int64s but this would then compile as a 64bit/64bit division which is worse.

Why isn't there a Int64div32to32 function?

Definition at line 163 of file fix24.cpp.

00164 {
00165     fixed24 result ;
00166     result.all = MulDiv(a.all,1<<24,b.all) ;
00167     return result ;
00168 }

fixed24 Fixed24Mul fixed24  a,
fixed24  b
 

signed multiplication

Author:
Gavin_Theobald (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/6/2005
Parameters:
two fixed24s [INPUTS]
None [OUTPUTS]
Returns:
FIXED24 result (arg1 * arg2) Scope: Only to be used in the FIXED24 class.

Errors: None (no overflow checks). Rounds

Definition at line 133 of file fix24.cpp.

00134 {
00135     fixed24             result;
00136     result.all = INT32((Int32x32To64(a.all,b.all)+0x800000)>>24) ;
00137     return result;
00138 }

double Fixed24ToDouble fixed24  a  ) 
 

General type conversion.

Author:
Gavin_Theobald (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/6/2005
Parameters:
FIXED24 argument [INPUTS]
None [OUTPUTS]
Returns:
double-precision value Scope: Only to be used in the FIXED24 class.

Errors: None

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

Definition at line 188 of file fix24.cpp.

00189 {
00190     return (double)a.all/(1<<24) ;
00191 }


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