| Home
| Previous
| Next
| Up

MGL_FixMul

Multiplies two fixed point number in 16.16 format

Declaration

fix32_t MGLAPI MGL_FixMul(
fix32_t f,
fix32_t g)

Prototype In

mgraph.h

Return Value

Result of the multiplication.

Description

Multiplies two fixed point number in 16.16 format together and returns the result. We cannot simply multiply the two 32 bit numbers together since we need to shift the 64 bit result right 16 bits, but the result of a FXFixed multiply is only ever 32 bits! Thus we must resort to computing it from first principles (this is slow and should ideally be re-coded in assembler for the target machine).

We can visualise the fixed point number as having two parts, a whole part and a fractional part:

FXFixed = (whole + frac * 2^-16)

Thus if we multiply two of these numbers together we get a 64 bit result:

(f_whole + f_frac * 2^-16) * (g_whole + g_frac * 2^-16) =
(f_whole * g_whole) +
(f_whole * g_frac)*2^-16 +
(g_whole * f_frac)*2^-16 +
(f_frac * g_frac)*2^-32

To convert this back to a 64 bit fixed point number to 32 bit format we simply shift it right by 16 bits (we can round it by adding 2^-17 before doing this shift). The formula with the shift integrated is what is used below. Natrually you can alleviate most of this if the target machine can perform a native 32 by 32 bit multiplication (since it will produce a 64 bit result).

See Also

MGL_FixDiv, MGL_FixMulDiv

Copyright © 2002 SciTech Software, Inc. Visit our web site at http://www.scitechsoft.com