Jump to content
  • Advertisement
Sign in to follow this  
mancubit

Approximation Floating Point Numbers with Integers

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

Unfortunately i haven't found any valueable information on this topic using google. So maybe you can help me:

I am searching for some information how floating point (or fixed point) numbers can be aproximated with integer numbers. So for example, if i know the floating point number is only between -1 and +1, how can i reasonably approximate this number with a 8bit integer number (maybe bitshifting it or something like that)? I am either interested in theoretical aspecs as well as real implementations.

I Hope i dont sound too weird asking such things. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
ok thats a little bit embarrassing - i thought it would be more complicated than that. Thanks for your help, solution sounds good to me

Share this post


Link to post
Share on other sites
The linear mapping that BuffaloJ gave would be my first answer too. However, a slight generalization might be useful in some situations, in order to allow certain regions of the interval to have more resolution than others. It's this:

* You have floating-point numbers that can fall in the interval [a,b].
* You have an unsigned integer type that can take values between 0 and N; for an n-bit number, N=2[sup]n[/sup]-1.
* What you're looking for is a function f from the interval [a,b] to the interval [0,N] satisfying,
- f(a)=0 and f(b) = N
- f is strictly increasing.

An example of such a function is the linear mapping,

f(x) = N*[ (x-a)/(b-a) ]

like what BuffaloJ gave you; this will give you uniform sampling, but other choices are possible as well. E.g.,

f(x) = N*[ (x-a)/(b-a) ][sup]2[/sup]

will dedicate more resolution to numbers at the top of the range, and less to those at the bottom,

f(x) = N*[ (x-a)/(b-a) ][sup]1/2[/sup]

will dedicate more to the bottom, and

f(x) = N*([2*(x-a)/(b-a) - 1][sup]1/3[/sup] + 1)/2

will concentrate more around the middle.

The sampling density around some floating point number 'x' is approximately the value of the derivative, df/dx(x). You get more resolution where 'f' is steep.

Share this post


Link to post
Share on other sites
Just so you know, fixed point is literally approximating non-integer values using integers. For example, with 16.16 fixed point (16 bits integer, 16 bits fraction), the value 1.0 is stored as 65536.

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!