frac function
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.
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).
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).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement