Skip to content

Seq.sortBy cannot handle sequences of floats containing NaN #370

Description

@darklajid

I stumbled upon these cases in a one-off fsx - I'm not regularly using F#. This might be entirely my fault.
That said:

Microsoft (R) F# Interactive version 12.0.30815.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

> [| 3.2; 1.5; nan; 4.7; nan; 8.5 |] |> Array.sortBy (fun x -> x);;
val it : float [] = [|nan; nan; 1.5; 3.2; 4.7; 8.5|]

Good.

> [| 3.2; 1.5; nan; 4.7; nan; 8.5 |] |> Seq.sort;;
val it : seq<float> = seq [nan; nan; 1.5; 3.2; ...]

Fine.

> [| 3.2; 1.5; nan; 4.7; nan; 8.5 |] |> Seq.sortBy (fun x -> x);;
val it : seq<float> = seq [3.2; 1.5; nan; 4.7; ...]

What? Why?

I would expect that Array.sortBy and Seq.sortBy behave the same. And I would expect that sortBy identity is the same as sort? What's going on here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions