I am learning Jason Hickey’s Introduction to Objective Caml.
It says
Matching against floating-point values is supported, but it is rarely used because of numerical issues
Ok, we can’t match floating-point values.
Then what if we need? How to do it then?
To expand on previous answers, you can use pattern matching with floats, like in this example:
Just be careful that pattern matching implicitly uses equality test, which is rarely what one wants when working with floats: when rounding errors accumulate, two floats are rarely exactly equal. So, you can use guards with the keyword
when, as illustrated in the above code.