Yes, pardon my quick typing.

More specifically, a case constant is not a _constant pattern_ (at least, not yet), it is just a constant case label. Constants are typed, and they carray both a type match and a value match.  When you say

    case 0

this is a constant for an int, and doesn't match a floating point zero (if the match target is `float`, it won't even compile.)  Similarly, `case 0.0` is a constant for a float, and is not applicable to a match target of int.  (We do have the usual tolerance for matching int constants to shorter int types, as before.)

We may generalize these to constant patterns in the future, but right now, these are constant case labels and their semantics are derived from that of existing case labels.

On 1/26/2023 10:25 AM, Guy Steele wrote:


On Jan 26, 2023, at 9:36 AM, Brian Goetz <[email protected]> wrote:

...

For comparing a variable to a constant, representational equality is the obvious interpretation; `case nnn` means "is it the number nnn".  This allows you to say `case NaN` and `case -0` and get the right answer (all of these relations agree on what to do about 1.0).

Careful: I think you had better say “case -0.0”; otherwise the constant expression “-0” will be reduced to “0” and only then converted to floating-point representation, producing +0.0.

Yes, floating-point is VERY fiddly.

—Guy

Reply via email to