Skip to content

INumber.Min(+QNaN, 1) returns 1 #98285

@skyoxZ

Description

@skyoxZ
float qNaN = BitConverter.Int32BitsToSingle(0x7FC00000);
Console.WriteLine(float.Min(qNaN, 1));

Double/Single/Half.Min(+QNaN, 1) correctly returns NaN but INumber.Min not:

/// <summary>Compares two values to compute which is lesser.</summary>
/// <param name="x">The value to compare with <paramref name="y" />.</param>
/// <param name="y">The value to compare with <paramref name="x" />.</param>
/// <returns><paramref name="x" /> if it is less than <paramref name="y" />; otherwise, <paramref name="y" />.</returns>
/// <remarks>For <see cref="IFloatingPoint{TSelf}" /> this method matches the IEEE 754:2019 <c>minimum</c> function. This requires NaN inputs to be propagated back to the caller and for <c>-0.0</c> to be treated as less than <c>+0.0</c>.</remarks>
static virtual TSelf Min(TSelf x, TSelf y)
{
// This matches the IEEE 754:2019 `minimum` function
//
// It propagates NaN inputs back to the caller and
// otherwise returns the larger of the inputs. It
// treats +0 as larger than -0 as per the specification.
if ((x != y) && !TSelf.IsNaN(x))
{
return x < y ? x : y;
}
return TSelf.IsNegative(x) ? x : y;
}

(another issue: search .. in INumber.cs to find a redundant dot)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Numericsin-prThere is an active PR which will close this issue when it is merged

    Type

    No type
    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