Jump to content
  • Advertisement
Sign in to follow this  
DarkMatter2008

frac function

This topic is 3491 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all, I've been looking at a piece of puedo code here:- http://freespace.virgin.net/hugo.elias/graphics/x_polygo.htm I've never come across a frac function before in the maths.h, what is it and what's the C equivilant? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
It returns the fractional part of the argument. Ie frac(3.14) will return 0.14. You can emulate it by something like

float frac(float f) {
int i = (int)f;
return f - i;
}

Of course this won't work for very large numbers, but for should for the purpose of the article.

Note that it's usually easier and faster to work with fixed-point math for the things mentioned in the article (in which case the frac() operation can be as simple as a single bitwise AND operation).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!