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

Fixed point goodness

Sign in to follow this  
VisualLR

96 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 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  


0 Comments


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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!