Determine fraction length of fixed-point binary

594 Views Asked by At

How to determine fraction length of fixed-point binary so that distinct entries of a group of decimal numbers (for example: 1, 0.456, 0.444) remain distinct after converting them from decimal to fixed-point binaries?

1

There are 1 best solutions below

0
On BEST ANSWER

You can get a bound by looking at the smallest gap between your numbers. For your example, $0.456-0.444=0.012$ If you use $n$ bits such that $2^{-n} \lt 0.012$ you are guaranteed that the representations will be different after rounding. In this case, we find $n=7, 2^{-n}=0.0078125$ and in fact $0.456 \approx 0.0111010_2, 0.444 \approx 0.0111001_2$, so this is the best we can do. Two numbers that are very close together could round away from each other and fewer bits might be needed. For example, if your numbers were $0.250001$ and $0.249999$ we would think we would need $19$ bits as $2^{-19}\approx 1.9 \cdot 10^{-6} \lt 0.000002$, but in fact $0.249999$ rounds down to $0.0_2$ while $0.250001$ rounds up to $0.1_2$ and we only need one bit.