Jump to content
• Advertisement

# getting absolute value

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

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

1. // float/doublex = fabs(x);x = abs(x);2.x = x < 0 ? -x: x;3.if ( x < 0 ) x = -x;4. // float/doublex = 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. // intx = (x ^ (x >> (sizeof(int) * 8 - 1))) - (x >> (sizeof(int) * 8 - 1));

did I miss one? =p

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
A4L
13
5. 5
• Advertisement

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633744
• Total Posts
3013657
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!