Skip to content

Conversation

@tannergooding
Copy link
Member

This isn't taking into account #68191 yet, that will happen as part of a separate work item after the next API review.

@ghost
Copy link

ghost commented Apr 19, 2022

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented Apr 19, 2022

Tagging subscribers to this area: @dotnet/area-system-numerics
See info in area-owners.md if you want to be subscribed.

Issue Details

This isn't taking into account #68191 yet, that will happen as part of a separate work item after the next API review.

Author: tannergooding
Assignees: tannergooding
Labels:

area-System.Numerics, new-api-needs-documentation

Milestone: -

Copy link
Contributor

@dakersnar dakersnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation looks good, skimmed the tests and they look good as well.

double ax = Abs(x);
double ay = Abs(y);

if ((ax > ay) || IsNaN(ay))
Copy link
Contributor

@dakersnar dakersnar Apr 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two questions:

  1. If ax was NaN and ay was 1.23, would the "(ax > ay)" condition return false? EDIT: Scratch this, you have a test case that confirms this behavior.
  2. If both ax and ay are NaN, NaN (ax) would be returned here. Does that contradict with the comment "It does not propagate NaN inputs back to the caller"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Yes, x cmp y always returns false if either x or y is NaN
  2. No, in the case that both are NaN, NaN is the thing to return

/// <param name="y">The value to compare with <paramref name="x" />.</param>
/// <returns><paramref name="x" /> if it is greater than <paramref name="y" />; otherwise, <paramref name="y" />.</returns>
/// <remarks>For <see cref="IFloatingPoint{TSelf}" /> this method matches the IEEE 754:2019 <c>maximumNumber</c> function. This requires NaN inputs to not be propagated back to the caller and for <c>-0.0</c> to be treated as less than <c>+0.0</c>.</remarks>
static abstract TSelf MaxNumber(TSelf x, TSelf y);
Copy link
Member

@stephentoub stephentoub Apr 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs on this are identical to the docs on MaxMagnitudeNumber, with the sole exception of saying that it matches maximumNumber instead of maximumMagnitudeNumber, but for that to be meaningful to me as a consumer I need to know what IEEE says those are :) Can we be more explicit in the summary about the comparison being performed in order to differentiate these?

Same for the comments below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also differs on This requires NaN inputs to be propagated vs This requires NaN inputs to not be propagated

I'll submit a follow up PR to update the docs to be more explicit in the summary.

Copy link
Member Author

@tannergooding tannergooding Apr 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'll update them in this PR. This isn't going to make the snap since Half.op_Modulus is still failing in CI only

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They both say "This requires NaN inputs to not be propagated back to the caller". Is that just a typo then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, I misread this as saying MaxNumber and Max docs were identical.

I did fix it up so Max, MaxNumber, and MaxMagnitudeNumber all differ in their docs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically:

  • Max returns the greater of x vs y, preferring NaN when present
    • Max(2, -3) returns 2
    • Max(2, NaN) returns NaN
  • MaxMagnitude returns the greater of x or y comparing using their absolute value (magnitude), preferring NaN when present
    • MaxMagnitude(2, -3) returns -3
    • MaxMagnitude(2, NaN) returns NaN
  • MaxNumber returns the greater of x vs y, not preferring NaN when present
    • MaxNumber(2, -3) returns 2
    • MaxNumber(2, NaN) returns 2
  • MaxMagnitudeNumber returns the greater of x or y comparing using their absolute value (magnitude), not preferring NaN when present
    • MaxMagnitudeNumber(2, -3) returns -3
    • MaxMagnitudeNumber(2, NaN) returns 2

@tannergooding tannergooding merged commit 85e715a into dotnet:main Apr 20, 2022
directhex pushed a commit to directhex/runtime that referenced this pull request Apr 21, 2022
…mber (dotnet#68217)

* Exposing MaxMagnitudeNumber, MaxNumber, MinMagnitudeNumber, and MinNumber

* Ensure Max, MaxMagnitude, Min, and MinMagnitude tests are covering the relevant scenarios

* Moving the floating-point AssertEqual helper from the Math/MathF tests into AssertExtensions

* Adding tests covering MaxMagnitudeNumber, MaxNumber, MinMagnitudeNumber, and MinNumber

* Disabling a few Half tests due to an issue around -0

* Disabling a few Half tests due to an issue around +0

* Fixing 67993 as the test helper had a bug where it used the wrong target type

* Fixing up the doc comment for Min/MaxMagnitudeNumber and Min/MaxNumber to clarify it doesn't propagate NaN
@ghost ghost locked as resolved and limited conversation to collaborators May 20, 2022
@tannergooding tannergooding deleted the generic-math-minmaxnumber branch November 11, 2022 15:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants