• entries
135
130
• views
52676

# Fixed point goodness

97 views

Last night I converted the fixed point math class my friend wrote from C to C++, it turned out pretty good, you can use it just as if it was a primitive data type:

fixed fxNum1 = 32;fixed fxNum2 = 2;fxNum1 *= fxNum2; // performs multiplication in fixed pointfixed fxRoot = fixed::sqrt( fxNum1 ); // fixed point sqrtfloat fN1 = (float)fxNum1; // converts fxNum1 to floating pointint iN1 = (int)fxNum2; // converts fxNum2 to intfloat fRoot = (float)fxRoot;

Fixed point numbers will only be converted into something else when you cast them into either (float) or (int), as long as you don't cast them, any operation you perform on them will be done as fixed point arithmetic.

I also converted my Vector and Matrix classes to use 'fixed' instead of 'float' last night. So AFAIK they're much faster now, I just need to run some tests.

There are no comments to display.

## Create an account

Register a new account