Jump to content
  • Advertisement
Sign in to follow this  

getting absolute value

This topic is 4709 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

I'm trying to adjust my camera and I have the z axis centroid which is sometimes a negative number and other times not. Since this function will be in my display() function, it gets called alot and I'm trying to figure out what the most efficient way is to get the absolute value of my smallest Z axis value (which can be pos or neg) so that I can multiply it by 2 and place my camera in that Z axis position away from my model (which should always be positive IIUC). I hope I'm on the right track as to how placing the camera should be done.

Share this post


Link to post
Share on other sites
Advertisement
The big mystery of finding the absolute value of x =)


1. // float/double
x = fabs(x);
x = abs(x);

2.
x = x < 0 ? -x: x;

3.
if ( x < 0 ) x = -x;

4. // float/double
x = sqrtf(x*x);
x = sqrt(x*x);

5. // float
__asm
{
fld x
fabs
fstp x
}

6. // float
*(((int *) &x)) &= 0x7fffffff;

7. // double
*(((int *) &x) + 1) &= 0x7fffffff;

8. // int
x = (x ^ (x >> (sizeof(int) * 8 - 1))) - (x >> (sizeof(int) * 8 - 1));




did I miss one? =p

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!