Skip to content

Why Double.Min(nan, -1.) = nan and Double.Max(nan, -1.) = nan? #19135

@64J0

Description

@64J0

Please provide a succinct description of the issue.

I just noticed this weird behavior when comparing nan with doubles.

Image

But, when I try using the Array.min, it gives the "correct" result (which is inconsistent):

Image

Repro steps

  1. Start fsi;
> open System;;
> Double.Min(nan, -1.);;
val it: float = nan

> Double.Max(nan, -1.);;
val it: float = nan

> let testArray : double array = [| 0.0; nan; 0.0; 0.0; 0.0; -0.3814976554; -0.0; 0.0 |];
val testArray: double array =
  [|0.0; nan; 0.0; 0.0; 0.0; -0.3814976554; -0.0; 0.0|]

> Array.min(testArray);;                                                                 
val it: double = -0.3814976554

Expected behavior

I was expecting that a number would be always bigger and less than any nan.

What is the rationale for the other way around?

Actual behavior

It's informed at the repro steps section.

This happens when using System.Numerics.Vector too:

Image

Known workarounds

Related information

Provide any related information (optional):

  • Operating system: Linux
  • .NET Runtime kind (.NET Core, .NET Framework, Mono): .NET 10
  • Editing Tools (e.g. Visual Studio Version, Visual Studio): -

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions