Jump to content
  • Advertisement
Sign in to follow this  
TheOddMan

1 / ( 2 ^ n )

This topic is 4499 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've hit a point in my project where I need to implement a formula and I can't see how I'm gonna do this one. The formula (as it says on the tin ) is: 1 / ( 2 ^ n ) ( That is one over two to the power of n ) where n is any of the set of real numbers. I'd consider a recurring function, but n isn't necessarily ( or even likely to be ) a whole number. Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Couldn't you do something like...
1.0f / (1 << n)

Although, this wouldn't work if n wasn't an integer.

Share this post


Link to post
Share on other sites
Quote:
Original post by deej21
Couldn't you do something like...
1.0f / (1 << n)

Although, this wouldn't work if n wasn't an integer.


Very original, I wonder what happends if N is a a negative number. Would the compiler actually shift it to the right instead, I don't think so.

Share this post


Link to post
Share on other sites
Quote:
Original post by StormArmageddon
If your using fixed point and assuming n>0 you could do (1>>n) where 1 would be the fixed point equivilant. Plus this would be really fast.


It should work for n >= 0.

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!