dotnet / dotnet/fsharp

List/Array/Seq.max/min/maxBy/minBy may return nan if the sequence starts with nan

Open
#13,207 16 comments 0 reactions 0 assignees View on GitHub
Area-Library
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

The position where NaN appears changes what Seq.max returns.

**Repro steps**

```fs
printfn $"{Seq.max [nan; 2.; 1.; 4.]}"
printfn $"{Seq.max [3.; nan; 1.; 4.]}"
printfn $"{Seq.max [3.; 2.; nan; 4.]}"
printfn $"{Seq.max [3.; 2.; 1.; nan]}"
```

**Expected behavior**

```
4
4
4
3
```

**Actual behavior**

```
NaN
4
4
3
```

**Known workarounds**

Filter away all NaNs first.

**Related information**

SharpLab
https://sharplab.io/#v2:DYLgZgzgNALiBOBXAdgHwA7wJbJmZABACQBEA3gMoCmAjgHQC2AhgB4EDayTyA3AQEx0+ARiEEALHQC6AXxIBYAFCYceQqUq1GrDgGYxXXgVF9Jshcuy58xctXrM27fX0F9Dp6XKUrr6u1qOemJuxgbc5kA=

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.