Skip to content

Conversation

@tannergooding
Copy link
Member

This is broken into a few commits and it may be easiest to review this per commit rather than altogether.

  • The first is largely a refactoring that moves the existing interface methods down to INumberBase as per API review. This includes fixing up the tests to use the right helper type.
    • Moving the interfaces required exposing new explicitly implemented APIs on most types that return constant true or false.
  • The second is purely a refactoring of the test declaration ordering to be consistent so we can actually easily see the coverage that already exists
  • The third is purely additional and adds test coverage for the new APIs added by the first commit
  • The final is likewise purely additional and adds the same coverage for System.Numerics.Complex
    • This one is standalone because it is larger, since Complex only implements INumberBase<T> and so needed more tests overall

@ghost
Copy link

ghost commented May 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 May 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 is broken into a few commits and it may be easiest to review this per commit rather than altogether.

  • The first is largely a refactoring that moves the existing interface methods down to INumberBase as per API review. This includes fixing up the tests to use the right helper type.
    • Moving the interfaces required exposing new explicitly implemented APIs on most types that return constant true or false.
  • The second is purely a refactoring of the test declaration ordering to be consistent so we can actually easily see the coverage that already exists
  • The third is purely additional and adds test coverage for the new APIs added by the first commit
  • The final is likewise purely additional and adds the same coverage for System.Numerics.Complex
    • This one is standalone because it is larger, since Complex only implements INumberBase<T> and so needed more tests overall
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.

Looks good to me! Looked less closely at the tests, but they seem robust.

public static class ExponentialFunctionsHelper<TSelf>
where TSelf : IExponentialFunctions<TSelf>
{
public static TSelf Exp(TSelf x) => TSelf.Exp(x);
Copy link
Contributor

Choose a reason for hiding this comment

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

Who uses these helpers in general? In what context are they useful?

Copy link
Member Author

Choose a reason for hiding this comment

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

These are specifically for testing and guarantee that the "static abstracts in interfaces" path is executed, that is the path users will hit by using the generic math feature

static bool INumberBase<BigInteger>.IsFinite(BigInteger value) => true;

/// <inheritdoc cref="INumberBase{TSelf}.IsInfinity(TSelf)" />
static bool INumberBase<BigInteger>.IsInfinity(BigInteger value) => false;
Copy link
Contributor

Choose a reason for hiding this comment

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

When the rework happens for BigInteger, I wonder if there is any value to introducing the concept of Infinity to handle all numbers above whatever finite limit we set for the type.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd expect that would be overall confusing to users, but its something we can discuss at that time.

}

[Fact]
public static void MaxNumberTest()
Copy link
Contributor

Choose a reason for hiding this comment

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

Only comparing to 1 in each of these tests might not lead to proper coverage, but as long as the 1 input follows a normal code path in each method, this should be fine. For example, if 1 was handled with some edge case in BigInteger.MaxNumber then this would raise an eyebrow, but it doesn't.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, there's going to be more tests added overall after the main feature work goes in.

This is more a "minimal subset" to ensure good coverage of the APIs and the normal edge cases.

@tannergooding tannergooding merged commit 8962e24 into dotnet:main May 20, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jun 20, 2022
@stephentoub stephentoub added the breaking-change Issue or PR that represents a breaking API or functional change over a previous release. label Nov 1, 2023
@ghost ghost added the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Nov 1, 2023
@jeffhandley
Copy link
Member

dotnet/docs#41835 was created for the breaking change document

@jeffhandley jeffhandley removed the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Jul 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Numerics breaking-change Issue or PR that represents a breaking API or functional change over a previous release. new-api-needs-documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants