Sign in to follow this  
mancubit

Approximation Floating Point Numbers with Integers

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
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 [i]f[/i] 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

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