Convert a real range to an integer range. Let's say that we have a set of integers in the range $[1, 4]$. Now, I have a function that will calculate a distance between two vectors, and this function returns a real number in the range $[0, 1]$.
Currently, to calculate the error made by this function, I convert the numbers from the real range $[0, 1]$ to the integer range $[1, 4]$ using the following mapping:
$$
M(x) =
\begin{cases}
    1,&\quad\text{if}~~~0~~~~~ \le x \le 0.25\\
    2,&\quad\text{if}~~~0.25 \lt x \le 0.5\\
    3,&\quad\text{if}~~~0.5~~ \lt x \le 0.75\\
    4,&\quad\text{if}~~~0.75 \lt x \le 1\\
\end{cases}
$$
But I think this is not really precise, because values such as $0.49$ will be converted to $2$ when they are closer to $3$.
I am looking for a better way to map values from the real range $[0, 1]$ to the integer range $[1, 4]$ that will not lose so much precision as the one above.
 A: With the information given, you can't do better. If you map an interval of reals to a finite set of discrete values, there will always be points of discontinuity. The smaller the number of those discrete values, the bigger the average size of the pre-image of a range value becomes.
In your example, it's obvious that if you use a 'sensible' mapping (something measurable), then you need to map at least an interval (or union of intervals) with aggregate length $\frac14$ to one of your $4$ values. So the mapping you gave is in some sense best, you have reached, but not exceeded, that limit.
No matter what you do, if you choose just $4$ possible mapping values, it will feel imprecise. Think of them as school grades. With just $4$ different grades available, as a teacher you'd have lots of cases where a small difference in 2 students' work quality would result in a different grade, even when the difference doesn't feel like "one grade".
Now, if you know or suspect something about the actual distribution of your value in the $[0,1]$, that might help you find a better mapping. For example, if values above $0.5$ are much less likey than values below, maybe have a mapping where the cutoff points are $0.1, 0.2, 0.6$ and $1$. 
My advise would be to think about what you actually need. Why are you converting $[0,1]$ values to discrete 'grades' when you are concerned about loss of accurracy? If you need discrate 'grades', maybe use more of them such that each 'jump' from one grade to the next doesn't feel as big. Maybe use an odd number of grades, if you think that having a 'middle grade' would be benficial to map values around $0.5$ to. 
None of those are generally better than your function. But depending on what else you know about the problem at hand, they might be able to better express what you want to achieve.
