F# - How to compare floats
问题 In F#. How to efficiently compare floats for equality that are almost equal? It should work for very large and very small values too. I am thinking of first comparing the Exponent and then the Significand (Mantissa) while ignoring the last 4 bits of the its 52 bits. Is that a good approach? How can I get the Exponent and Significand of a float? 回答1: An F# float is just a shorthand for System.Double . That being the case, you can use the BitConverter.DoubleToInt64Bits method to efficiently