JDT wrote:
It seems that using floats as the first tupelo for an STL map (shown
below) can cause problems but I don't remember what the problems
were.
The only thing I can think of is that if you expect two different
results of a calculation to lead to the same number (and ultimately
to the same stored in the map value), you may be in for a surprise.
Due to rounding errors in the FPU the mathematically equivalent
calculations can lead to different numbers internally.
Example, given that 'a' is 1.f and 'b' is 2.f, the expressions
(a + 2.f/3) and (b - 1.f/3) _can_ give you different results.
Is it common practice to use a structure like below? I would
appreciate if you can share your experience using such a structure.
Thanks.
std::map<float, int> m;
I _never_ saw a 'map' where 'float' would be the Key type. I cannot
claim to have seen all code in the world, and even a significant part
of it, so I cannot attest to "commonality" of the practice.
V
makes sense. For example, the following table needs to be sorted in
the ascending order of the 1st tuple (i.e. Values). So I can simply
automatically. Do people often have similar needs or are there other
appreciated.