// I am assuming something like this
typedef long FixedPoint;
// assuming long is 32 bits
#define FP_INTEGER_PRECISION 16
#define FP_DECIMAL_PRECISION 16
#define FP_INTEGER_MASK 0xFF00
#define FP_DECIMAL_MASK 0x00FF
FixedPoint operator*(FixedPoint op1,FixedPoint op2)
{
FixedPoint op2int = op2 > FP_DECIMAL_PRECISION;
FixedPoint op2dec = op2 & FP_DECIMAL_MASK;
FixedPoint product = 0;
product = op1 * op2dec;
product = product > FP_DECIMAL_PRECISION;
product += op1 * op2high;
return product;
}
I haven't had time to test this code...so please respond here or email me if it has any errors. Also, please note that the potential for overflow is enormous. It is no different than multiplying 2 integers, but it is easy to forget that the highest 32 bit fixed point number (if 16x16 format is assumed) is the same as a 16 bit number, so 300*254 doesn't fit.
[This message has been edited by Xai (edited October 17, 1999).]