Knocking off two more vestiges of legacy switch

Guy Steele guy.steele at oracle.com
Wed Sep 14 04:05:45 UTC 2022


+1 on this suggestion. I believe it is the only approach that could make switch on floats at all useful, and it would be very useful, as Joe says, for expressing special cases in math libraries clearly.

—Guy

On Sep 13, 2022, at 1:07 PM, Joe Darcy <joe.darcy at oracle.com<mailto:joe.darcy at oracle.com>> wrote:

On 9/13/2022 9:55 AM, Brian Goetz wrote:

It is common for math library methods to have a preamble to screen out special values (infinities, NaN, 0.0, 1.0, etc.).

This would be a reasonable use of a switch on float/double switch.



Which raises some questions (again) of the semantics of constant patterns for exotic floating point values, especially (again) negative zero.


In a switching context, I think there is a stronger case for distinguishing between +0.0 and -0.0. The operational semantics I'd recommend are to desugar, say a float switch, to an int switch on the Float.floatToIntBits mapping of the float case labels. Float.floatToIntBits, as opposed to Float.floatToRawIntBits, normalized all NaN representations to a single value.

-Joe

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-observers/attachments/20220914/e07e4982/attachment-0002.htm>


More information about the amber-spec-observers mailing list