Sign in to follow this  
Wizumwalt_

getting absolute value

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

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

Sign in to follow this