Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Fixed point goodness

Sign in to follow this  


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 point

fixed fxRoot = fixed::sqrt( fxNum1 ); // fixed point sqrt

float fN1 = (float)fxNum1; // converts fxNum1 to floating point
int iN1 = (int)fxNum2; // converts fxNum2 to int

float 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.
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!