Skip to content

Commit 2521f81

Browse files
forkidsyme
authored andcommitted
Equality is 0 (#4493)
* Create a test that shows broken comparison on float32 * fix comparison of float32
1 parent 4952f84 commit 2521f81

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/fsharp/FSharp.Core/prim-types.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4167,7 +4167,7 @@ namespace Microsoft.FSharp.Core
41674167
else (# "ceq" e1 e1 : int #)
41684168
when ^T : float32 = if (# "clt" e1 e2 : bool #) then (-1)
41694169
elif (# "cgt" e1 e2 : bool #) then (1)
4170-
elif (# "ceq" e1 e2 : bool #) then (1)
4170+
elif (# "ceq" e1 e2 : bool #) then (0)
41714171
elif (# "ceq" e2 e2 : bool #) then (-1)
41724172
else (# "ceq" e1 e1 : int #)
41734173
when ^T : char = if (# "clt.un" e1 e2 : bool #) then (-1) else (# "cgt.un" e1 e2 : int #)

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,3 +816,16 @@ type RangeTests() =
816816
if System.UIntPtr.Size >= 8 then RangeTestsHelpers.unsigned (System.UIntPtr System.UInt64.MinValue) (System.UIntPtr System.UInt64.MaxValue)
817817

818818

819+
open NonStructuralComparison
820+
821+
822+
[<TestFixture>]
823+
type NonStructuralComparisonTests() =
824+
825+
[<Test>]
826+
member __.CompareFloat32() = // https://github.com/Microsoft/visualfsharp/pull/4493
827+
828+
let x = 32 |> float32
829+
let y = 32 |> float32
830+
let comparison = compare x y
831+
Assert.AreEqual(0, comparison)

0 commit comments

Comments
 (0)