CBFalconer said:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
My apologies for the confusion: that last sentence was supposed to have
the word "why" just before the word "does".
....
And a possible implementation of 32 bit floating point could
express 3.0 as (hex):
7e 80 00 00
in place of:
00 00 00 03 (hi byte first, integer)
and these patterns will have a hard time indexing the same location
in a jump table.
The expressions used in case labels are required to be converted to the
promoted type of the controlling expression before comparison (the
conversion would normally occur at compile time). Therefore, the fact
that those case label expressions might have a different representation
than the controlling expression before conversion is irrelevant.
I'll readily concede that having a controlling expression that is a
floating point type would make it less likely for jump tables to be
feasible, though it would still be possible in certain special cases. So
what? The same is true if the controlling expression has the type
intmax_t and the case label expressions have no simple pattern. The
standard does not require implementation by jump tables, it only allows
implementation by jump tables.
If the standard were changed to allow non-integral controlling
expressions in switch() statements, that change would not in any way
prevent the use of jump tables for any switch() statement that is
allowed under the current rules, if a jump table happens to be a good
way to implement that statement.
The key issue with allowing floating point controlling expressions is
not whether it would be feasible to support them, but whether it would
be a good idea to encourage people to use them. Writing a switch()
statement with a floating point controlling expression would be a bad
idea, even if it were allowed, for precisely the same reason it would be
a bad idea to write the corresponding series of if-else statements.
That's because the conditions of the corresponding if()'s would compare
floating point values for equality, a reasonable thing to do only in
certain special cases.