List/Array/Seq.max/min/maxBy/minBy may return nan if the sequence starts with nan
See original GitHub issueThe position where NaN appears changes what Seq.max returns.
Repro steps
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
Issue Analytics
- State:
- Created a year ago
- Comments:16 (16 by maintainers)
Top Results From Across the Web
python - Why does max() sometimes return nan and ...
The reason is that max works by taking the first value as the "max seen so far", and then checking each other value...
Read more >NaN - JavaScript - MDN Web Docs
The NaN global property is a value representing Not-A-Number. ... There are five different types of operations that return NaN :.
Read more >How to Fix Pandas Standard Deviation Returning NaN
Another reason why pandas standard deviation may return NaN is if there is insufficient data to calculate the standard deviation.
Read more >Watch out for NaNs - The Rust Programming Language Forum
That's because due to rounding errors it ends up taking a square root of a tiny negative number, and sqrt is defined to...
Read more >Cost function turning into nan after a certain number of iterations
Well, if you get NaN values in your cost function, it means that the input is outside of the function domain. E.g. the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Missed this bit. This does seem like a bug and an undesirable one at that. If someone is willing to log an issue, then we should probably look at this and make a determination.
@edgarfgp, I’ve taken that on, see #13558. So far I’ve only added tests, but that by and of itself exhibited some behavior that may need addressing.
@dsyme/@vzarytovskii, considering that .NET as a whole is moving to more conformance towards IEEE 754:2019, I think it’s probably best not to mimic the bug from LINQ. Besides, if that one in particular relies on
Math.Min
, there’s https://github.com/dotnet/runtime/pull/70865 by @tannergooding, which fixes that behavior.That’s also my understanding. It would otherwise be quite surprising w.r.t. the basic rule with
NaN
: if either operand isNaN
, returnNaN
.